Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In classic ASP, is there a way to handle errors at application level?

In classic ASP, is there a way to handle error at application level?

Is there guidelines for handling error / exceptions in classic ASP 3 ? The Server.GetLastError() not a lot to work with...

I am looking for something like the Application_Error() found in an ASP.Net Global.asax.

Any equivalent in a global.asa ? Classes to intelligently log the error ? Like an old Enterprise library exception handling for ASP3...

Hey, I am a dreamer !

Thanks a lot for any pointers

like image 795
PBelanger Avatar asked Oct 21 '09 21:10

PBelanger


People also ask

How errors are handled in the application?

Error handling helps in handling both hardware and software errors gracefully and helps execution to resume when interrupted. When it comes to error handling in software, either the programmer develops the necessary codes to handle errors or makes use of software tools to handle the errors.

Which event is used for application level exception handling?

If an exception is not handled at the page level then it will be propagated to the application level and at the application level in the global. aspx file there is an application_Error event where the exception can be handled.

What is application level error?

An Application-level exception occurs when a recoverable error is encountered, for example, the wrong type of input data, arithmetic exceptions etc.

Is Classic ASP obsolete?

Classic ASP, however, is no longer being developed by Microsoft at all – it has long since been replaced by ASP.NET in 2002, a newer alternative.


2 Answers

Unfortunately Global.ASA only provides Application_OnStart, Application_OnEnd, Session_OnStart and Session_OnEnd methods. No error handling.

The closest you can get (AFAIK) is using the Custom Errors feature in IIS to point to other file or url to handle the error.

Custom Errors Image

In my opinion, is too much trouble. This is a missing feature that makes me migrate some websites, only for the peace of mind of knowing that the site is working without errors.

like image 56
Eduardo Molteni Avatar answered Sep 21 '22 12:09

Eduardo Molteni


try:
    some code that can raise an error
except:
    do error handeling stuff
finally:
    clean up, close files etc

Can be emulated in vbscript as follows:

class CustomErrorHandler
    private sub class_terminate
        if err.number > 0 then
            do error handeling stuff
        end if 
        clean up, close files etc
    end sub
end class    


with new CustomErrorHandler
    some code
    ...
end with    

How does this work? The 'class_terminate' method will be called when the newly created instance goes out of scope. This happens either when the interperter hits the 'end with' statement or when the callstack gets unwinded due to an error. It's less pretty then the native python approach but it works quite well and isn't to ugly.

For top level error handling you can use the same technique. This time don't use the with statement but create a global instance of your error handler. Beware that the ASPError object provided server.getLastError() isn't the same as the vbscript err object and is only available after IIS has done its server.transfer to the 500:100 error handler and has come back to your page to collect the garbage. Example handler:

class cDebugger
  public sub do_debug
     ' print debug data here
  end sub
  public sub class_terminate
    if server.getlasterror().Number <> 0 then
        response.clear
        call do_debug
    end if
  end sub
end class
like image 35
Joost Moesker Avatar answered Sep 21 '22 12:09

Joost Moesker