處理 JScript 的錯誤
您的 Microsoft JScript 程式碼必須檢查 Connection 物件 Errors 集合的 Count 屬性。 如果值大於 0,請逐一查看集合,並列印值,就像您在任何其他語言中一樣。
<!-- BeginErrorExampleJS -->
<%@ Language=JScript %>
<HTML>
<HEAD>
<title>Error Handling Example (JScript)</title>
</HEAD>
<BODY>
<h1>Error Handling Example (JScript)</h1>
<%
var cnn1 = Server.CreateObject("ADODB.Connection");
var errLoop = Server.CreateObject("ADODB.Error");
var strError = new String;
// Intentionally trigger an error.
cnn1.Open("nothing");
if (cnn1.Errors.Count > 0) {
// Enumerate Errors collection and display
// properties of each Error object.
for (var i = 1; i < cnn1.Errors.Count; i++) {
errLoop = cnn1.Errors(i);
strError = "Error #" & errLoop.Number + "<br>" +
" " + errLoop.Description + "<br>" +
" (Source: " & errLoop.Source & ")" + "<br>" +
" (SQL State: " & errLoop.SQLState + ")" + "<br>" +
" (NativeError: " & errLoop.NativeError + ")" + "<br>";
if (errLoop.HelpFile == "")
strError = strError +
" No Help file available" +
"<br><br>";
else
strError = strError +
" (HelpFile: " & errLoop.HelpFile & ")" & "<br>" +
" (HelpContext: " & errLoop.HelpContext & ")" +
"<br><br>";
Response.Write("<p>" & strError & "</p>");
}
}
%>
</BODY>
</HTML>
<!-- EndErrorExampleJS -->