Hello!
This question is similar to your earlier one about catching .NET exceptions in JavaScript, and our answer is similar as well - consider catching the exception in JavaScript and allowing .NET code to inspect it. For example:
and then:
As you can see, the host and the script engine can work together!
Good luck!
This question is similar to your earlier one about catching .NET exceptions in JavaScript, and our answer is similar as well - consider catching the exception in JavaScript and allowing .NET code to inspect it. For example:
engine.Execute(@"
function tryCatch(func) {
try {
return { isSuccess: true, returnValue: func() };
}
catch (exception) {
return { isSuccess: false, exception: exception };
}
}
");
dynamic result = engine.Evaluate(@"tryCatch(function() { throw { foo: 123, bar: 456 }; })"); if (!result.isSuccess) { Console.WriteLine(result.exception.foo); Console.WriteLine(result.exception.bar); } else { Console.WriteLine(result.returnValue); }
Good luck!