---
title: "Handling Errors in JScript | Microsoft Docs"
ms.prod: sql
ms.prod_service: connectivity
ms.technology: connectivity
ms.custom: ""
ms.date: "01/19/2017"
ms.reviewer: ""
ms.topic: conceptual
dev_langs:
- "JScript"
helpviewer_keywords:
- "errors [ADO], JScript"
- "JScript error handling [ADO]"
ms.assetid: 3de527e5-2e65-4ab0-9b7f-6d317c4478de
author: MightyPen
ms.author: genemi
---
# Handling Errors in JScript
Your Microsoft® JScript® code must check the **Count** property of the **Connection** object's **Errors** collection. If the value is greater than 0, iterate through the collection and print the values as you would in any of the other languages.
```
<%@ Language=JScript %>
Error Handling Example (JScript)
Error Handling Example (JScript)
<%
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 + "
" +
" " + errLoop.Description + "
" +
" (Source: " & errLoop.Source & ")" + "
" +
" (SQL State: " & errLoop.SQLState + ")" + "
" +
" (NativeError: " & errLoop.NativeError + ")" + "
";
if (errLoop.HelpFile == "")
strError = strError +
" No Help file available" +
"
";
else
strError = strError +
" (HelpFile: " & errLoop.HelpFile & ")" & "
" +
" (HelpContext: " & errLoop.HelpContext & ")" +
"
";
Response.Write("" & strError & "
");
}
}
%>
```