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

New Post: Raise a custom exception

$
0
0
Hello, Torsten!

You can easily expose a function that throws a host exception. For example:
engine.Script.throwBadArg = new Action<string, string>((message, paramName) =>
{
    thrownew ArgumentException(message, paramName);
});
Keep in mind that exceptions thrown in this manner are likely to be wrapped by ScriptEngineException by the time they reach the host, so you'll have to use InnerException or GetBaseException() to examine them.

On the other hand, if you need to catch and examine exceptions in JavaScript code, we recommend that you use JavaScript exceptions. Being normal JavaScript objects, they offer nearly infinite flexibility. That said, it is possible to catch and examine host exceptions in script code. See this thread for more information.

Good luck!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>