901 questions
2
votes
0
answers
156
views
Why catch block is ignored, and std::terminate is invoked? [duplicate]
I have a program that works as expected if compiled by GCC, but behaves weirdly after porting to Visual Studio.
The program throws an exception from noexcept(false) destructor (I know that it is a bad ...
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 ...
3
votes
1
answer
168
views
Conditional operator with a throwing branch in Visual C++ 2026
My program changed its behavior after updating Visual Studio to the latest version (2026).
Simplifying it, I got the following minimal example, which contains a ternary operator with a throw in ...
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?
...
45
votes
9
answers
87k
views
How to throw an exception with a status code?
How can throw an error with options or a status code and then catch them?
From the syntax here, it seems we can through the error with additional info:
new Error(message, options)
So, can we throw ...
4
votes
1
answer
400
views
using throw in a constexpr or a consteval function in order to generate compile-time error
The problem
Using static_assert to generate compile-time error is not always easy because it requires a constant expression as first argument. I found, on StackOverflow, several example where throw ...
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 ...
2
votes
1
answer
168
views
"Not all control paths return a value" when calling a function which throws [duplicate]
Example:
int foo() { throw 0; }
int bar() { foo(); }
foo here doesn't get a warning, while bar gets the error "must return a value". More typically, bar would have some return statements ...
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 ...
0
votes
1
answer
36
views
Progress compile option 'requireReturnValues' fails with error throwing
I have set the compile option requireReturnValues="Error".
I tried to compile the following example code but it doesn't pass the option:
METHOD PUBLIC LOGICAL checkValue(i_cValue AS CHAR):
...
-3
votes
1
answer
89
views
Is throw reachable after return statement in using context? [duplicate]
Is this throw statement even reachable?
It's not showing as unreachable by compiler.
public static async Task<List<string>> GetSomething(int id)
{
using (DbContext context = new ...
0
votes
0
answers
247
views
How to properly handle nested try/catch blocks within nested stored procedures?
I have multiple layers of nested stored procedures, each with a try...catch block within them. However, I want each of these nested stored procedures to be able to properly run their own transaction ...
45
votes
5
answers
76k
views
"rxjs" observable.throw is not a function - Angular4
I've been learning Angular 4 and everything was going smoothly until I tried to implement catch handling in a service. I'm trying to use "rxjs" catch and throw but I've got an undefined function error ...
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 ...
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(...