Show Dialog When Crashing #16375
-
Hi Everyone! Thanks for your help and input in advance! I have a small application I've made with Avalonia, I'm attempting to catch any exceptions in place and handle them gracefully, however I've occasionally missed some and my app crashes. I'm currently catching the exceptions globally by doing the following: try
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
catch (Exception e)
{
Log.Fatal(e, "An unhandled exception occurred.");
throw;
}
finally
{
Log.CloseAndFlush();
} This currently does allow me to get information about the crash by reading my logs, but I would like a way to present a dialog to the user if the app crashes so I can present some information about the exception that occurred and what they might be able to do to get support. I haven't been able to figure out a way to handle this. I've tried creating a window in the try / catch above, but Avalonia doesn't like being re-initialized. I've tried catching exceptions in the Any suggestions? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
At this line Alternatively, if you handle Dispatcher.UnhandledException, you still will have some time to show dialog in the same process. But it highly depends on the error - some might still crash the app, and another might cause inconsistent state. |
Beta Was this translation helpful? Give feedback.
-
I also handle this and present a window to user after the crash: All you need is to reopen your program and pass arguments and handle that in startup to present your error. See: https://github.com/sn4k3/UVtools/blob/master/UVtools.UI/App.axaml.cs#L172 |
Beta Was this translation helpful? Give feedback.
-
Thanks guys! |
Beta Was this translation helpful? Give feedback.
I also handle this and present a window to user after the crash:
All you need is to reopen your program and pass arguments and handle that in startup to present your error.
See: https://github.com/sn4k3/UVtools/blob/master/UVtools.UI/App.axaml.cs#L172
And: https://github.com/sn4k3/UVtools/blob/master/UVtools.UI/Program.cs#L184