Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: How do I catch an exception if my script has an error

$
0
0
Hi,

My code:

Imports System.Xml
Imports Microsoft.ClearScript

Public Class WebForm1
Inherits System.Web.UI.Page

Dim xml As XmlDocument = New XmlDocument
Dim engine As Windows.JScriptEngine = New Windows.JScriptEngine

Public Sub Initialize()
    engine.AddHostObject("xml",xml)

    Try
        engine.execute("xml.LoadXml('</>/sales id=""1""/>');")
    Catch e As Exception
        Response.Write(e.Message)
    End Try

    If xml.InnerXml.ToString <> "" Then Response.Write(xml.SelectSingleNode("//sales").Attributes.GetNamedItem("id").InnerText)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

End Class

I know the loadxml statement is wrong (means I am loading incorrect XML in it). But in this case VS breaks during run and it sends me to some clearscript source code. How can I trap this error. I do the same using Jint and I can trap the error and the project does not stop running. Thanks.

Viewing all articles
Browse latest Browse all 2297

Trending Articles