901 questions
663
votes
14
answers
602k
views
What is the difference between `throw new Error` and `throw someObject`?
I want to write a common error handler which will catch custom errors thrown on purpose at any instance of the code.
When I did throw new Error('sample') like in the following code
try {
throw ...
361
votes
11
answers
301k
views
Throwing exceptions from constructors
I'm having a debate with a co-worker about throwing exceptions from constructors, and thought I would like some feedback.
Is it OK to throw exceptions from constructors, from a design point of view?
...
161
votes
7
answers
121k
views
Why can I not throw inside a Promise.catch handler?
Why can't I just throw an Error inside the catch callback and let the process handle the error as if it were in any other scope?
If I don't do console.log(err) nothing gets printed out and I know ...
140
votes
14
answers
31k
views
Should I use an exception specifier in C++?
In C++, you can specify that a function may or may not throw an exception by using an exception specifier. For example:
void foo() throw(); // guaranteed not to throw an exception
void bar() throw(...
134
votes
7
answers
40k
views
How do exceptions work (behind the scenes) in c++
I keep seeing people say that exceptions are slow, but I never see any proof. So, instead of asking if they are, I will ask how do exceptions work behind the scenes, so I can make decisions of when to ...
119
votes
4
answers
6k
views
In C++, if throw is an expression, what is its type?
I picked this up in one of my brief forays to reddit:
http://www.smallshire.org.uk/sufficientlysmall/2009/07/31/in-c-throw-is-an-expression/
Basically, the author points out that in C++:
throw "...
112
votes
3
answers
33k
views
What is the difference between C++03 `throw()` specifier and C++11 `noexcept`?
Is there any difference between throw() and noexcept other than being checked at runtime and compile time respectively?
This Wikipedia C++11 article suggests that the C++03 throw specifiers are ...
104
votes
7
answers
141k
views
T-SQL Throw Exception
I am facing the famous 'Incorrect syntax' while using a THROW statement in a T-SQL stored procedure. I have Googled it and checked the questions on StackOverflow but the solutions proposed (and ...
95
votes
3
answers
73k
views
Is there a throws keyword in C# like in Java? [duplicate]
Possible Duplicate:
how to use Java-style throws keyword in C#?
i have a function where an exception occurs
say for example
private void functionName() throws Exception
{
// some code that ...
89
votes
8
answers
58k
views
When to catch the Exception vs When to throw the Exceptions?
I have been coding in Java for a while now. But sometimes, I don't understand when I should throw the exception and when should I catch the exception. I am working on a project in which there are lot ...
73
votes
6
answers
50k
views
"throw new Warning" in JavaScript?
At the moment I'm extending my JavaScript project with error handling. The throw statement is playing an important role here:
throw new Error("text"); // Error: text
However, can I also throw a ...
70
votes
5
answers
16k
views
What is generator.throw() good for?
PEP 342 (Coroutines via Enhanced Generators) added a throw() method to generator objects, which allows the caller to raise an exception inside the generator (as if it was thrown by the yield ...
67
votes
3
answers
104k
views
rethrowing python exception. Which to catch?
I'm learning to use python. I just came across this article:
http://nedbatchelder.com/blog/200711/rethrowing_exceptions_in_python.html
It describes rethrowing exceptions in python, like this:
try:
...
62
votes
19
answers
115k
views
Is it okay to throw NullPointerException programmatically? [closed]
When there is a post-condition, that return value of a method must not be null, what can be done?
I could do
assert returnValue != null : "Not acceptable null value";
but assertions could be turned ...
62
votes
3
answers
9k
views
What can you throw in Java?
Conventional wisdom says you can only throw objects that extend Throwable in Java, but is it possible to disable the bytecode verifier and get Java to compile and run code that throws arbitrary ...