Reputation: 41
I just want to display ALL crash messages in a messagebox instead of using 100 time try catch for each function. Is it possible to just add like some lines of code once so it displays the crashmessage in a messagebox?
I have this code but it looks like it doesn't work or only works for some messages?
Private Sub OnThreadException(ByVal sender As Object, ByVal e As ThreadExceptionEventArgs)
MessageBox.Show(e.Exception.Message)
End Sub
Upvotes: 0
Views: 103
Reputation: 54477
You can't just add that method and expect it to do something because it is supposed to handle an event, so you need to actually register it to handle that event.
There's a better option though. Handle the UnhandledException
event of the application, which you can do by clicking the View Application Events button on the Application page of the project properties.
That's going to shut down the application on every exception though. What you should be doing is considering under what situations an exception can reasonably be expected, catch those and continue on after appropriate cleanup, then using the UnhandledException
event to catch those that you can't predict. It's not appropriate to just not bother thinking about exceptions at all but it's also not appropriate to catch exceptions where one cannot reasonably be expected.
Upvotes: 4