"No, you can't use try-catch in ASP" :)
Main Topics
Browse All TopicsDoes ASP provide the capability to do a Try Catch Finally. I know ASP.net has it, buy I am using just .asp pages. I can put in the following code and this is the error I get:
<%
...
Try
...Some database code here
Catch SQLexc as sqlexception
Response.write(SQLexc)
...
Finally
...Close database connections
%>
At the catch, I get the following error:
__________________________
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
Catch SQLexc as sqlexception
------------^
__________________________
This may be a simple answer of "No, you can't use try-catch in ASP" or maybe I am coding it wrong.
Nate
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Not true--you can do it with server-side JScript:
http://msdn.microsoft.com/
FtB
If you look at my first post, that is what I said--not possible with VBScript, but may be possible with JScript.
I should have been clearer--I realize the example offered is in VBSCript, and try / catch is not supported with that language. For the sake of being complete-- the title of the question was "Try Catch in ASP"--I was pointing out that try / catch is supported with JScript and ASP.
FtB
In ASP you need to turn on error handling by using one of the following...
On Error Resume Next - keep executing script / don't stop on error
On Error Goto 0
Or add "On Error Resume Next" before your code and then at the end of your script check for errors like this...
If Err.Number <> 0 Then
' Error occured / check which error / error handling goes here
End
Good Luck...
--------
D_M_D
You can have both jscript and vbscript on the same page
To integrate jscript into a vbscript page, use the following
<%@ language="vbscript" %>
<Script language="jscript" runat="server">
function dispHello()
{
return "hello";
}
</script>
<%
response.write(dispHello()
%>
The above code defines a function in jscript and calls it from vbscript.
Remember jscript is case sensitive, and if you know c or java its easier to learn jscript.
and it supports try .. catch.
Hope this helps
Cheers
Kaliyappan
You don't need to use both JavaScript and VBScript. You can use just VBScript. Just add "On Error Resume Next" where you would add the "Try" statement. Then add your error check where you would add the "Catch" statement like below...
<%
Dim i
' Turn on error Handling
On Error Resume Next
For i = 0 to 10
' SOme COde Here
Next
' Error Handler
If Err.Number <> 0 Then
' Error Occured / Trap it
End If
%>
--------
D_M_D
It is not quite the same:
JScript is a server-side language often used with ASP. JavaScript is most often a client-side scripting langauge.
The former is a more robust langauge with greater capabilities.
http://www.faqts.com/knowl
http://www.hostbyte.com/we
Business Accounts
Answer for Membership
by: fritz_the_blankPosted on 2004-06-27 at 07:22:53ID: 11409957
Try / Catch is not supported in VBScript. Perhaps with JScript you might be able to.
Fritz the Blank