views:

303

answers:

2

I have a web user control which my aspx page contains. During testing I discovered a exception being thrown. (The general rule that is in place, is that when an exception occurs the user is redirected to a excpetion page detailing the error)

Once the excpetion was handled in my User Control I wanted to throw it to the page where the parsing and redirect could occur safely. I do this in other circumstances by using the Global Asax, Application_Error to deal with the redirect etc. however all that happened when I threw the exception from the user contorl was I got a horrible javascript type dialog with the exception message.

To work around this I declared an Event which is then raised from the user control with the exception as the parameter. I can successfully parse the expception to the required format and redirect the user to the exception page.

My question(s) are these

  1. Why does throwing the exception from the user control only result in the javascript dialog and not the Global.asax error handling kicking in.

  2. Is there a way to force consumers of the control to handle my custom error event? Simialr to a "MustImplement" -----a "MustHandle" kind of affair?

A: 

I'm not versed in ASP.NET but I'll give it a shot:

  1. Why does throwing the exception from the user control only result in the javascript dialog and not the Global.asax error handling kicking in.

The error is raised on the client side, your error handling takes place on the server side. Unless you implement an AJAX-y callback that kicks in upon errors, the server isn't notified of any client-side errors. This doesn't seem to be the default behaviour in ASP.NET. You might check out Microsoft's AJAX library, surely they already have a mechanism for such things in place.

  1. Is there a way to force consumers of the control to handle my custom error event? Simialr to a "MustImplement" -----a "MustHandle" kind of affair?

Simple answer: no.

Konrad Rudolph
+1  A: 
  1. Why does throwing the exception from the user control only result in the javascript dialog and not the Global.asax error handling kicking in.

Because there is a page error during an asynchronous postback, here's a good article on Error Handling in ASP.Net Ajax Applications.

2.Is there a way to force consumers of the control to handle my custom error event? Simialr to a "MustImplement" -----a "MustHandle" kind of affair?

This explains how to handle asynchronous postback errors in the Global.asax.

Phaedrus