在 ASP Classic 中是否可以进行 try-catch 之类的错误处理? [英] Is try-catch like error handling possible in ASP Classic?

查看:24
本文介绍了在 ASP Classic 中是否可以进行 try-catch 之类的错误处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP Classic 中有哪些用于错误处理的选项?

What options are there in ASP Classic for error handling?

例如:

我正在使用 Mail.SendMail 功能,但是在打开测试服务器时它不起作用,这是正常的.我想测试是否可以邮寄,如果不能,则继续和/或显示一条消息.

I'm using the Mail.SendMail function but when switching on the testing server it doesn't work, which is normal. I want to test if mailing is possible, if not then continue and/or show a message.

有什么想法吗?

推荐答案

有两种方法,您可以在 JScript 或 VBScript 中编写代码,它们确实具有构造,或者您可以在代码中捏造它.

There are two approaches, you can code in JScript or VBScript which do have the construct or you can fudge it in your code.

使用 JScript,您将使用以下类型的构造:

Using JScript you'd use the following type of construct:

<script language="jscript" runat="server">
try  {
    tryStatements
}
catch(exception) {
    catchStatements
}
finally {
    finallyStatements
}
</script>

在您的 ASP 代码中,您可以通过使用 on error resume next 在您尝试并检查 err.Number 的捕获点来伪造它,例如:

In your ASP code you fudge it by using on error resume next at the point you'd have a try and checking err.Number at the point of a catch like:

<%
' Turn off error Handling
On Error Resume Next


'Code here that you want to catch errors from

' Error Handler
If Err.Number <> 0 Then
   ' Error Occurred - Trap it
   On Error Goto 0 ' Turn error handling back on for errors in your handling block
   ' Code to cope with the error here
End If
On Error Goto 0 ' Reset error handling.

%>

这篇关于在 ASP Classic 中是否可以进行 try-catch 之类的错误处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆