- Home /
Unhandled exception event doesn't trigger?
Is this one of those things that aren't supposed to work in Unity?
[InitializeOnLoad]
public class EditorOnLoad {
static EditorOnLoad()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += currentDomain_UnhandledException;
}
static void currentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
GlobalManager.KillPeer();
}
}
There's probably no Exception that isn't handled by the Editor
Good point. Unfortunately there is no equivalent EditorApplication event that one can listen to either, as far as I can see.
well... what type of exceptions do you expect? If you're working on some kind of framework, maybe the code in the framework that calls the custom functions can catch everything by wrapping all calls into try-catch
Nothing specific, just anything that inherits from System.Exception.
I can wrap the whole thing into try-catch, but that's really not the way to go imo. I don't need to call the custom function in all (or any) try-catch blocks. I need it to be called when an error is thrown. Using excessive try-catch blocks makes it much harder to debug with Unity because it (often) hides the line at which the error ocurred.
when I said type.. I didn't mean c# type, but what kind of situation you're trying to catch.
Attaching yourself to the AppDomain seems wrong anyway, as it's not your AppDomain. If you want something like a save scripting environment, start your own AppDomain and put everything in there.
using try-catch isn't hiding the line number more than catching it centrally.
I can't shake the feeling you're trying to crack a nut with a sledgehammer.
What are you trying to achieve?
Answer by Bunny83 · Jan 12, 2014 at 01:14 AM
How about using Application.RegisterLogCallback? Don't forget to check the logtype
Your answer
Follow this Question
Related Questions
custom event delegate - convertible error 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Issues when hooking GUI to code 0 Answers
How to add an Interactable script component to a GameObject programmatically 1 Answer