118 questions
55
votes
5
answers
26k
views
catch exception by pointer in C++
I found that there are three ways to catch an exception, what are the differences?
1) catch by value;
2) catch by reference;
3) catch by pointer;
I only know that catch by value will invoke two ...
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 ...
60
votes
8
answers
66k
views
Exception handling : throw, throws and Throwable
Can any of you explain what the differences are between throw, throws and Throwable and when to use which?
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 ...
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 ...
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 ...
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 ...
43
votes
12
answers
8k
views
Incorrect stacktrace by rethrow
I rethrow an exception with "throw;", but the stacktrace is incorrect:
static void Main(string[] args) {
try {
try {
throw new Exception("Test"); //Line 12
}
...
3
votes
1
answer
327
views
What causes the different behaviors between "var" and "let" when assign them a returned value of a function which throws an error
Please find the code in the image below.
1. Assign the returned value of a function, which throws an error actually, to the variable 'withLet' that declared by using keyword 'let'.
2. call 'withLet', ...
51
votes
3
answers
26k
views
Deprecated throw-list in C++11
Just as I can see in cppreference, the classic "throw" declaration lists is now deprecated in C++11. What is the reason of leaving this mechanism and how should I have to specify what exceptions ...
38
votes
1
answer
18k
views
Does throw inside a catch ellipsis (...) rethrow the original error in C++?
If in my code I have the following snippet:
try {
doSomething();
} catch (...) {
doSomethingElse();
throw;
}
Will the throw rethrow the specific exception caught by the default ellipsis handler?...
34
votes
3
answers
1k
views
Why does throwing 2 exceptions in a row not generate an unreachable code warning?
Why do the following lines of code not create a compiler warning?
void Main()
{
throw new Exception();
throw new Exception();
}
As I see it, the compiler should inform you that the second throw ...