The worst part of Classic ASP in VBScript is Error Handling.
You need to type “on error resume next”, then, check, on every line, check if the previous one generates an error using [If Err.Number <> 0 then …]. That’s a real pain.
When you need solid error handling inside an ASP – VBScript sub or function, there’s a very simple method you can apply.
Yes you can! It’s called JScript, it’s ECMAScript 3 compatible, and it just works.
Also, it’s totally compatible with your existing VBScript application, that will be able to call that JS method without any issue. Even all your application VBScript variables will be shared between VB and JS.
100% VBScript file:
<% function fct1 fct1 = true on error resume next ' do something that can crash dim i : i = 1 i = i / 0 if err.number <> 0 then fct1 = false response.write err.number & "<br>" response.write err.description & "<br>" end if on error goto 0 end function sub sub1 dim value : value = fct1() response.write "result: " & value end sub call sub1() %>
Just, watch out as JScript is case sensitive, VBScript is not.
2 thoughts on “How to use Try Catch in ASP Classic”
Thanks for this. Still have a couple of old asp classic apps I maintain. Always handy to have some useful tips. Especially JS and IIS based to help while I move them over to something new.
Thank-you, thank-you, thank-you