Best practices for exception handling?
On Apr 29, 2011, at 1:08 PM, Axel Rauschmayer wrote:
Would it make sense to standardize more exception/error types, for example to add a MissingParameterError in ES.next?
No proposal yet for demanding actual parameter count match formal, so this would not be used.
It can't be used from built-ins already spec'ed, since it would be an incompatible runtime change. We're trying to avoid those (typeof null == "null" is the current exception), in favor of early errors when migrating.
On 30.04.2011 0:22, Axel Rauschmayer wrote:
Would it make sense to standardize more exception/error types, for example to add a MissingParameterError in ES.next? No proposal yet for demanding actual parameter count match formal, so this would not be used. Right. I would use it when I do my own checking. This idea is mainly motivated by Java having several predefined exceptions with descriptive names that are easy to reuse.
With JavaScript, is throwing a string considered bad style (now or in the future)? That is, is throwing a new Error(msg) better than throwing msg directly?
Why? In general when you don't need a complex structure of an exception to analyze, the ability to throw strings IMO is better than Java's long-long line of WhatAnNiceMidnightOn30OfAprilExceptionIn.
Dmitry.
Would it make sense to standardize more exception/error types, for example to add a MissingParameterError in ES.next?
No proposal yet for demanding actual parameter count match formal, so this would not be used.
Right. I would use it when I do my own checking. This idea is mainly motivated by Java having several predefined exceptions with descriptive names that are easy to reuse.
With JavaScript, is throwing a string considered bad style (now or in the future)? That is, is throwing a new Error(msg) better than throwing msg directly?
Axel
On 4/29/11, Dmitry A. Soshnikov <dmitry.soshnikov at gmail.com> wrote:
On 30.04.2011 0:22, Axel Rauschmayer wrote:
With JavaScript, is throwing a string considered bad style (now or in the future)? That is, is throwing a new Error(msg) better than throwing msg directly?
Why?
To get a meaningful error.stack
?
Would it make sense to standardize more exception/error types, for example to add a MissingParameterError in ES.next?