View Single Post
  #1 (permalink)  
Old February 20th, 2007, 10:26 AM
flegel flegel is offline
Registered User
Join Date: Feb 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exception handling in a custom control


I am writing a ASP.Net custom control (vs2005). I am implementing the usual methods such as Render,
LoadPostData etc. and that goes fine.
However, I just cannot find how I should handle exceptions for a custom control in a good way.
I want to be able to catch / thow exceptions in my control, and then catch/show those in the
page my control is in, without getting a error-page.

For example, when I make an event for my control, and I implement
code for this event in the page my control is in. How can I do this in
such a way that I dont get to see the default error page of .NET (and also not a custom error page).
I simply want to catch the exception in my page and (for example) show it in a label or so.
So, something like this below:

public partial class MyPage : System.Web.UI.Page

   public void MyControl1_TestEvent (EventArgs e)
        // ... do something

     catch (Exception ee)
       lblError.Text = ee.Message;


What is the usual way to implement this? How do professional component developers deal with this subject?