Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Global Exception Trapping
Message
From
26/12/2007 10:08:44
 
 
To
24/12/2007 12:52:01
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
01276890
Message ID:
01277503
Views:
20
Ok thanks for the info. I will have to think of a methodology that will be appropriate then for this scenario. I've done a good bit of error trapping in .NET at this point and I'm not thinking in terms of the VFP paradigm. But I like to trap at the immediate level for specific error types and then apply a higher level trap for items that slip through but maybe not at the highest level, basically defensive programming. I'll be thinking thorugh this for this applicatin we are working on and once the methodology is worked out I will be able to use it from now on.

Thanks for providing food for thought.

Bill

>Merry Christmas to you too, Bill. =0)
>
>First, let me mention that the try/catch around the Application.Run(new MyForm()) will correctly catch stuff that you've neglected to wrap in a try/catch further down in your app, but at that point, you can't do much else other than display or log the error. The application will quit after that ... AFAIK, there's nothing you can do about that.
>
>Now, on to your other question ... I can't think of any way to have global error trapping at the WinForm level. AFAIK, .NET does not have an "ON ERROR" that is analagous to VFP's. I initially thought about maybe putting a try/catch around the call to the Form, like this:
>
>try
>{
>    MyForm o = new MyForm();
>    o.Show();
>}
>catch (Exception ex)
>{
>    MessageBox.Show(ex.Message);
>}
>
>
> ... but I didn't think about that for very long, because that will obviously not work ... it will only catch exceptions in the instantiation and loading of the Form. After that, nothing ... because everything else is event driven and control has already returned back to the code after the o.Show().
>
>So, that's not going to work either. I think you're out of luck ... you'll have to think about error trapping in a .NET way, not a VFP way. <g>
>
>~~Bonnie
>
>
>
>
>
>>While I'm thinking about it, is there a way to do a 'global" trap of errors at the Winform level, i.e. to make sure all errors in a form are trapped at the from level?
>>
>>BTW, Merry Christmas. :-)
>>
>>Bill
>>
>>>Bill,
>>>
>>>We do basically the same thing. It will trap any errors that aren't handled in other parts of your code. This is mainly used as a catch-all in case you've forgotten a try/catch elsewhere in your program.
>>>
>>>In addition we have Error classes that handle displaying the Error message ... client-side errors get displayed to the user, server-side errors get logged in the Application Event Log.
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>Hi Einar,
>>>>
>>>>Thanks for the reply. Yes, I can see doing that, but I'm not sure that will trap all lower level errors and have to believe there is a way to insure that they are trapped. I will research it more and we can see if anyone else weighs in with more info.
>>>>
>>>>Bill
>>>>
>>>>>I think the answer to your question is no, but I always wrap my main in a try catch to catch (and log) any exception that is unhandeled. Something like this:
>>>>>
>>>>>[STAThread]
>>>>>static void Main()
>>>>>{
>>>>>	try
>>>>>	{
>>>>>		Application.EnableVisualStyles();
>>>>>		Application.SetCompatibleTextRenderingDefault(false);
>>>>>		Application.Run(new MyForm());
>>>>>	}
>>>>>	catch (Exception ex)
>>>>>	{
>>>>>		MessageBox.Show(ex.Message);
>>>>>	}
>>>>>}
>>>>>
>>>>>
>>>>>
>>>>>>In ASP.NET we can use the Application_Error() method of Global.asax to implement global error trapping to insure any untrapped errors still get trapped and addressed.
>>>>>>
>>>>>>Is there an equivalent methodology in a Winforms application for trapping "untrapped" execptions at a global level so they can be addressed?
>>>>>>
>>>>>>Thanks,
>>>>>>Bill
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform