Hi omnamasivaya,
If you're wondering how to handle .NET exceptions in script code, here's one way:
Note that this works only in
Both features are new in ClearScript 5.4, but if you're stuck with an older version, it should be fairly easy to code up your own version of
Good luck!
If you're wondering how to handle .NET exceptions in script code, here's one way:
engine.AddHostType(typeof(WebClient)); engine.AddHostType(typeof(Console)); engine.Execute(@" client = new WebClient(); try { ret = client.DownloadString('http://example.com'); } catch (ex) { if (ex.hostException) { Console.WriteLine(ex.hostException.GetBaseException().Message); } } ");
V8ScriptEngine
. An alternative that works with other script engines is HostFunctions.tryCatch
; you can download the latest API reference here.Both features are new in ClearScript 5.4, but if you're stuck with an older version, it should be fairly easy to code up your own version of
tryCatch
. You can see ClearScript's implementation here.Good luck!