Link to home
Start Free TrialLog in
Avatar of PLavelle
PLavelle

asked on

Global_Error in Web applications?

I am reading about Error Events in ASP.NET Web applications in preparation for a Microsoft certification test. The book mentions that there are three error events in a Web application, a Page_Error, Global_Error, and Application_Error. I can find the Application_Error event and the Page_Error event, but I see no Global_Error event. Is this just a mistake in the book?
Avatar of GoodJun
GoodJun

Global_Error is the same as Application_Error. You can change the name. The vs.net only use Application_Error in the IDE, you can type over use Global_Error
Avatar of PLavelle

ASKER

If i rename it, I can't get the Global_Error event to fire, but I can get the Application_Event to fire before it was renamed
There is not much document on the Global_Error stuff. Forget my last comments from memory. Here are some related copied from link:
http://www.dotnetjunkies.com/Article/4073C212-9B02-4229-89F5-92F4F2EDBAD4.dcik

Every Web Form and Web Service project has a global.asax unit. Double clicking that item in the solution explorer will reveal a design surface just like a component. After clicking the link to the code you see the global class, it descends from the System.web.HttpApplication. This HTTPapplication-object will receive all requests and assemble the response. Requests will be passed one by one. The processing of the request is done in a number of steps. After each step an event is fired. In the global class generated by VS.NET you will see a number of methods whose name starts with Application, they respond to events in the application as a whole. The HTTPApplication class has a large array of event-handlers, these events are fired by the actual object which is handling the request. ASP.NET can load multiple global objects in one application; a request is always processed by just one of the global objects. To program the HTTPapplication you write code in the generated Application methods. Your methods can subscribe to the global events, provided they have the right signature.

They are different despite what is beig said above ... I will explain the difference

Page_Error is generated by the base of the page

Application_Error is generated by a runtime generated subcass of httpapplication (global.asax)
Global Error is generated via the Application object (which HttpApplication is derived from)

Although the other two are similar they are different in signature, where they are thrown from, and the fact that the global error is 1 delegate for everything where as the application error is only for exceptions within that instance of the httpapplication (there is more than one of these in an asp.net application) ...

public event EventHandler Error; (raises Arument of EventArgs)
public static event ThreadExceptionEventHandler ThreadException; (raises argument ThreadExceptionEventArgs)

the global exception also includes the original exception in the event args where as the application exception makes you cal getlasterror
i have made a search in yahoo and google, not much usefull info founded, just this from a forum elsewhere:

http://staff.develop.com/candera/weblog2/CommentView.aspx?guid=c5bc0e98-c906-47e1-a8a5-63641d43729e

regards
Do you need further information than what I gave on global errors ?
Yeah I guess I'm still having trouble really understanding what they are both used for.
ok ...

Application_error is per httpapplication object in scope .. Also you have to call server.getlasterror() here.

the globalerror aka threaderror is on the application object and is global in scope. It has many uses. One of the big ones is that I can write exception handling classes that I bind to it which work in either a forms app or a webforms app. Also you are given the exception in your event args. Also if there are errors within my domain that are not part of my http application I will receive those errors (example being if I start up a thread)
Can you post some code that will cause the Global error event to fire and not the Application event?
start up a thread that is outside of the httpapplication and let an unhandled exception occur.
dim t as new Thread(addressof CauseError)
t.Start()


public sub CauseError()
Thread.Sleep(100000)
throw new system.exception("dying")
end sub

I believe the httpapplication will not pick this up.
nothing seems to pick it up. I just get a 'Request Details' page.
Actually, when the exception occurs it gives me an Unhandled Exception dialog.
do you have something handling the global error area ? the threadexception event ?
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
is there further help needed here ?