This project has moved. For the latest updates, please go here.

Gathering error/exception information when using .Execute

Mar 19, 2014 at 6:10 PM
Edited Mar 19, 2014 at 6:10 PM
What is the preferred/best way to get error information from the script when using .Execute?

Catching 'ScriptEngineException' works... sort of, but it gives very unhelpful data. No line number (from the script itself), no error text that might have been raised or thrown by the script, etc. What it does seem to give is whatever error the interpreter might have thrown.

Here is an example...
1) Exception Type: Microsoft.ClearScript.ScriptEngineException EngineName: VBScriptEngine ErrorDetails: __Object does not support the requested invocation operation__ IsFatal: False Message: Object does not support the requested invocation operation Data: System.Collections.ListDictionaryInternal TargetSite: Void ThrowScriptError(Microsoft.ClearScript.IScriptEngineException) HelpLink: NULL Source: ClearScript HResult: -2146190593 Trace: at Microsoft.ClearScript.ScriptEngine.ThrowScriptError(IScriptEngineException scriptError) at Microsoft.ClearScript.Windows.WindowsScriptEngine.ThrowScriptError(Exception exception) at Microsoft.ClearScript.Windows.WindowsScriptEngine.<>c__DisplayClass14.<ScriptInvoke>b__13() at Microsoft.ClearScript.ScriptEngine.ScriptInvoke(Action action) at Microsoft.ClearScript.Windows.WindowsScriptEngine.ScriptInvoke(Action action) at Microsoft.ClearScript.Windows.WindowsScriptEngine.Execute(String documentName, String code, Boolean evaluate, Boolean discard) at Microsoft.ClearScript.ScriptEngine.Execute(String documentName, Boolean discard, String code) at Microsoft.ClearScript.ScriptEngine.Execute(String documentName, String code) at Microsoft.ClearScript.ScriptEngine.Execute(String code) at EmbeddedScript.Execute() in []EmbeddedScript.cs:line 101 2) Exception Type: System.NotSupportedException Message: Object does not support the requested invocation operation Data: System.Collections.ListDictionaryInternal TargetSite: System.Object InvokeHostMember(System.String, System.Reflection.BindingFlags, System.Object[], System.Object[], System.Globalization.CultureInfo) HelpLink: NULL Source: ClearScript HResult: -2146233067 Trace: at Microsoft.ClearScript.HostItem.InvokeHostMember(String name, BindingFlags invokeFlags, Object[] args, Object[] bindArgs, CultureInfo culture) at Microsoft.ClearScript.HostItem.InvokeMember(String name, BindingFlags invokeFlags, Object[] args, Object[] bindArgs, CultureInfo culture) at Microsoft.ClearScript.HostItem.<>c__DisplayClass3e.<System.Reflection.IReflect.InvokeMember>b__3d() at Microsoft.ClearScript.ScriptEngine.HostInvoke[T](Func`1 func) at Microsoft.ClearScript.Windows.WindowsScriptEngine.HostInvoke[T](Func`1 func)
The call stack is useless, because the error was thrown by the script. Column and line number of the script would be excellent.

Any ideas?
Coordinator
Mar 19, 2014 at 6:37 PM
Edited Mar 19, 2014 at 6:45 PM
Hi TooSlow,

The ErrorDetails property of ScriptEngineException should contain the information you're looking for. However, Windows script engines (JScript and VBScript) only provide this information if you enable script debugging. To do so, pass WindowsScriptEngineFlags.EnableDebugging to the script engine's constructor.

By the way, please see here for more information.

Cheers!
Mar 19, 2014 at 6:51 PM
Well, I suppose that is good and bad news, but it gets me to where I need to be, thanks again!