Custom Controls Exception handling

M

mjcast

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
custom controls are caught and handled by the page in the best way??
 
M

mortb

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
 
M

mjcast

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top