Subj : Re: try catch blocks To : =?ISO-8859-1?Q?Georg_Maa=DF?= From : Brendan Eich Date : Thu May 15 2003 01:07 pm Georg Maaß wrote: > Brendan Eich wrote: > >> SpiderMonkey supports an extension to ECMA: catch guards. If you write >> >> try { >> . . . >> } catch (e if e instanceof SQLException) { >> // here we know e is an SQLException >> } catch (e) { >> // this is the "catch-all" clause >> } finally { >> // code here runs no matter how control leaves the try-catch chain >> } >> >> I don't recall whether Rhino supports this extension. >> >> /be > > > Will this awful hack remain in JS 2.0? Why is this an "awful hack"? In JS1, it's necessary unless you want to foist the requirement to have a catch-call clause that re-throws e on every programmer who uses catch. Consider Amit's example, written using ECMA-262 Edition 3 only: try { /something complex that may throw arbitrary exceptions/; } catch (e) { if (e instanceof SQLException) { deal with the wanted exception; } else { throw e; } } finally { clean up; } Now tell me why it's "awul" to save the programmer from the error-prone requirement to write the if-else-rethrow boilerplate. > There it is not necesary, if it is implemented like known from C++ an > Java. Yes, of course -- JS2 is quite a different language. What made your comment relevant to JS1? /be .