キャッチする例外の型を指定するには
Firefoxではcatchに条件式が書けるので、以下のように例外の型を指定できます。
var Exception1 = function() { }; var Exception2 = function() { }; try { // throw new Exception1(); throw new Exception2(); } catch(e if e.constructor == Exception1) { alert('catch Exception1'); } catch(e if e.constructor == Exception2) { alert('catch Exception2'); }
これをIEやOperaなどでもやりたいんですけど、どうすればいいんでしょう?やはり一つのcatch(e)を用意して、ifで振り分けるんでしょうか。