Error / Popup Detection

My application does not cover all exception scenarios. At run time, a pop-up window sometimes appears that displays an error for ex: "System Null Link Exception" or "File or directory damaged and unreadable." As soon as an error window appears, it will not disappear until the user responds with buttons.

I want to catch this exception and do not want to show these error windows to users.

+6
source share
4 answers

You can catch all exceptions at the AppDoamin level by subscribing to the UnhandledException event

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); 
+4
source

You need to wrap your code in a try {} catch (Exception e) {} block so that you can catch the error yourself.

Example:

 try { // all of my code } catch ( Exception e ) { // show my own error dialog } 
+4
source

It looks like you need to go back through your code and look at the exception handling. Either there are sections of code that are not inside the try/catch , or you have several try/catch blocks that do not handle all possible exceptions.

You need to make sure that when you end these sections of code with try/catch blocks, you are not just eating errors, but writing them down. You do not want your application to have unexpected errors without any action, because these unforeseen errors can leave your application in a vulnerable state. Sometimes it's better to let your application crash than to hide these errors.

Here is a good article on using try/catch :

http://msdn.microsoft.com/en-us/library/ms173160.aspx

When you implement try/catch , make sure that you also consider entering finally to clear any connection information or other code that needs to be closed. It will look like this:

 try { //Your existing code } catch (Exception ex) { //Here is where you log the error - ex contains your entire exception so use that in the log } finally { //Clean up any open connections, etc. here } 

Note that the catch block catches a general Exception , so all errors that were not detected above (in more specific catch blocks) should be detected here.

+1
source

Try replacing all your MessageBox.Show() statements with something like Logger.LogInfo(ex.Message); . Use, for example, a logging solution, such as Log4Net .

0
source

Source: https://habr.com/ru/post/888231/


All Articles