Deprecated throw-list in C++11

For more detailed reasoning, see: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3051.html As expressed in the national body comment above, exception specifications have not proven useful in practice. There are numerous discussions of the problems with exception specifications in C++ (see, e.g., [Sutter02], [Boost03]), but the main issues are: Run-time checking: C++ exception specifications are checked at runtime rather than at … Read more

Is it okay to throw NullPointerException programmatically? [closed]

I would recommend you never throw NullPointerException by yourself. The main reason not to do this, as Thorbjørn Ravn Andersen says in a comment below, is that you don’t wan’t to mix ‘real, bad NPEs’ with NPEs thrown intentionally. So, until you’re confident that you’re able to recognize ‘valid’ NPE, I’d recommend to use IllegalArgumentException … Read more

What is the difference between C++03 `throw()` specifier and C++11 `noexcept`?

Exception specifiers were deprecated because exception specifiers are generally a terrible idea. noexcept was added because it’s the one reasonably useful use of an exception specifier: knowing when a function won’t throw an exception. Thus it becomes a binary choice: functions that will throw and functions that won’t throw. noexcept was added rather than just … Read more

What is the difference between `throw new Error` and `throw someObject`?

The difference between ‘throw new Error’ and ‘throw someObject’ in javascript is that throw new Error wraps the error passed to it in the following format − { name: ‘Error’, message: ‘String you pass in the constructor’ } The throw someObject will throw the object as is and will not allow any further code execution … Read more

What causes the different behaviors between “var” and “let” when assign them a returned value of a function which throws an error

Declarations of var variables get hoisted – the variable name initialization gets hoisted to the top of the containing function (or, if no function, to the top of the outer block). So var withVar = (function() {throw ‘error!’})() is parsed by the interpreter as var withVar; withVar = (function() {throw ‘error!’})() The same is not … Read more

Incorrect stacktrace by rethrow

Throwing twice in the same method is probably a special case – I’ve not been able to create a stack trace where different lines in the same method follow each other. As the word says, a “stack trace” shows you the stack frames that an exception traversed. And there is only one stack frame per … Read more

Difference between C++03 throw() specifier C++11 noexcept

Exception specifiers were deprecated because exception specifiers are generally a terrible idea. noexcept was added because it’s the one reasonably useful use of an exception specifier: knowing when a function won’t throw an exception. Thus it becomes a binary choice: functions that will throw and functions that won’t throw. noexcept was added rather than just … Read more