Subj : Re: Throwing host exception from host object To : Larry Blanchette From : Igor Bukanov Date : Wed Mar 17 2004 11:47 am Larry Blanchette wrote: > In rhino, I would like throw from a host object my own scriptable types as > catchable exceptions of "my type" in javascript. I seems that > > extending EvaluatorException > > and using > > Context.throwAsScriptRuntimeEx(ex); > > is the path to follow but it does not allow me to propagate my type. The > exception is caught as either "internalError" in the case of an evaluator > exception and "JavaException" otherwise. Do I need to extend ScriptRuntime > and override getCatchObject(Context cx, Scriptable scope, Throwable t) to > handle and convert my exceptions (didn't want to go there)? > > So if have > > class MyExceptionType extends ScriptableObject > > and in host object I throw > > Context.throwAsScriptRuntimeEx(myScriptable); // illegal > > > then i would > > try { > host.causeExceptions(); > } catch(exception) { > if(excetion instanceof MyExceptionType) { > // got it > } > } Note also that Rhino supports ECMAScript script extension that can be used to rewrite that as try { host.causeExceptions(); } catch(exception if excetion instanceof MyExceptionType) { // got it } catch(exception if excetion instanceof MyExceptionType2) { // got it } catch(exception if myExceptionCheck(excetion)) { // got it } catch (exception) { // optional catch-all } Effectively you can use "if arbitrary-boolean-expression" to add a condition-specific handler. Regards, Igor .