Exception Handling in forms

P

PromisedOyster

I would like to be able to trap all exceptions that may occur in a form
whilst a windows form is in scope. Once the exception is trapped I want
to output a log line, close the form down and then allow the user to
continue using the application.

frm2 frm1 = new frm1.Show();
frm2 frm2 = new frm2.Show();

public class frm1: MyForm
{
}


public class frm2: MyForm
{
}

public class MyForm: System.Windows.Form
{
public MyForm()
{
try
{
}
catch
{
// output log line
}
}
}

The above example will catch any exceptions in the constructor but not
any once the form is loaded.
 
P

PromisedOyster

Thanks Rakesh

I want to be able to catch all exceptions within the form itself (or
rather, the form that all our forms are derived form). In this way,

(1) We dont have to put try/catch blocks all over the place
(2) If an exception is thrown, the form will close down and any other
open form will remain open. As opposed to closing down the whole
application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top