例外
ちゃんとJava側で発生した例外もJavaScriptの例外として再現されました。
さっきのJSPの呼び出し部分を以下のように変えて
try { var result = eval( scriptlet ); var plainResult = toJSON( result ); resultTag.value = unescape( plainResult.replace(/\\/g, '%') ); if (result.javaClass == "org.asyrinx.brownie.jsonrpc.sample1.SampleParam1") { alert(result.param1); } } catch( e ) { resultTag.value = "Exception occured:" + "\ntypeof exception on javascript is " + (typeof e) + "\nconstructor is " + e.constructor + "\ne.name=" + e.name + "\ne.number=" + e.number + "\ne.message=" + e.message + "\ne.description=" + e.name + "\nexception is: [" + e + "]"; }
あと、selectに throwException というのoptionも追加します。
んで、SampleServiceに以下のメソッドを追加。
public void throwException(SampleParam1 param1) { throw new RuntimeException(param1.getParam1()); }
で、throwExceptionを実行してやると、こんな風に表示されます。
Exception occured: typeof exception on javascript isobject constructor is function Error() { [native code] } e.name=java.lang.RuntimeException e.number=undefined e.message=java.lang.RuntimeException: 例外を生成させてみる e.description=java.lang.RuntimeException exception is: [java.lang.RuntimeException: 例外を生成させてみる]
なるほど。