How do I catch an exception if my script has an error

Feb 21, 2014 at 5:12 AM
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.
Coordinator
Feb 21, 2014 at 8:17 PM
Greetings!

To prevent Visual Studio from breaking into the debugger in this situation, go to "DEBUG" -> "Exceptions..." and uncheck both boxes to the right of System.Runtime.InteropServices.COMException under "Common Language Runtime Exceptions".

Good luck!
Marked as answer by shripaldalal on 2/21/2014 at 6:35 PM
Feb 22, 2014 at 2:36 AM
Thanks it worked like a charm! Truly awesome project which was long due from Microsoft for dotNet developers.