all groups > asp.net building controls > april 2005 >
You're in the

asp.net building controls

group:

Custom Controls Exception handling


Custom Controls Exception handling mjcast
4/21/2005 1:39:06 PM
asp.net building controls:
I am creating a bunch of custom controls that will be used by user to display
Personalized data. The page that will host the controls will contain anywhere
from 6 custom controls to 2 custom control. I want the page to handle all
exceptions coming from the custom controls.

What is the best way to do this so that all exceptions thrown out of the
Re: Custom Controls Exception handling mortb
4/22/2005 12:00:00 AM
One way would be to have try catches in the custom controls and have them
always throw an yourCustomControlException which has the control's exception
as an inner exception.

hope this helps,
mortb

[quoted text, click to view]

Custom Controls Exception: My Solution mjcast
4/22/2005 12:07:03 PM
I have done it this way(since my first post).

The custom controls have an event, ErrorEvent. Which I expose to the page,
so that the page can subscribe to the event and run code whenever an
exception is thrown in any of the custom controls.
In the custom controls I have try..catch blocks, once an exception occurs,
in the catch block I run this code;
catch(Exception ex)
{
//call the Error method to expose the exception
Error(ex);
}
The exception is bubbled out of the control through the event, and the page
consumes it according to the exception.
Note: I am already using mutliple custom exceptions to distinguish between
exceptions that are caused by data related issues, and exceptions where I
want an error message to appear and processing to stop due to problems with
the data.

Thanks, any opinions on this will be greatly appreciated.

[quoted text, click to view]
AddThis Social Bookmark Button