在ASP Classic中可以尝试尝试错误处理吗? [英] Is try-catch like error handling possible in ASP Classic?

查看:149
本文介绍了在ASP Classic中可以尝试尝试错误处理吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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代码中,您可以使用错误恢复,尝试在检查点检查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:

<%
Dim i
' Turn on 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 ' But don't let other errors hide!
   ' Code to cope with the error here
End If
On Error Goto 0 ' Reset error handling.

%>

这篇关于在ASP Classic中可以尝试尝试错误处理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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