Questions tagged [nested-exceptions]
26 questions
43
votes
9 answers
Catching an exception that is nested into another exception
I want to catch an exception, that is nested into another exception.
I'm doing it currently this way:
} catch (RemoteAccessException e) {
if (e != null && e.getCause() != null && e.getCause().getCause() != null) {
MyException etrp =…
user321068
40
votes
9 answers
Best way to check whether a certain exception type was the cause (of a cause, etc ...) in a nested exception?
I am writing some JUnit tests that verify that an exception of type MyCustomException is thrown. However, this exception is wrapped in other exceptions a number of times, e.g. in an InvocationTargetException, which in turn is wrapped in a…

Yang Meyer
- 5,409
- 5
- 39
- 51
25
votes
5 answers
Why doesn't C++ use std::nested_exception to allow throwing from destructor?
The main problem with throwing exceptions from destructor is that in the moment when destructor is called another exception may be "in flight" (std::uncaught_exception() == true) and so it is not obvious what to do in that case. "Overwriting" the…

anton_rh
- 8,226
- 7
- 45
- 73
13
votes
4 answers
Should exceptions be chained in C++?
I just finished work on a C++-program where I've implemented my own exceptions (although derived from std::exception). The practice I've applied when one exception causes a chain reaction, propagating the error upwards and giving rise to other…

gablin
- 4,678
- 6
- 33
- 47
12
votes
2 answers
Using RAII to nest exceptions
So the way to nest exceptions in C++ using std::nested_exception is:
void foo() {
try {
// code that might throw
std::ifstream file("nonexistent.file");
file.exceptions(std::ios_base::failbit);
}
catch(...) {
…

bames53
- 86,085
- 15
- 179
- 244
4
votes
1 answer
Nested Exception vs modern (Java SE 7) exceptions
Question
What are the advantages and disadvantages of exceptions with context vs nested exceptions?
Why I care
As a developer who doesn't have a background in or know the background of Java, I have stumbled upon a possible opportunity to update an…

Key Lay
- 366
- 3
- 13
3
votes
1 answer
Under what circumstances does EXCEPTION_RECORD link to another nested exception?
The documentation for _EXCEPTION_RECORD says about one of it's members, struct _EXCEPTION_RECORD *ExceptionRecord
A pointer to an associated EXCEPTION_RECORD structure. Exception records can be chained together to provide additional information…

Tobi
- 2,591
- 15
- 34
3
votes
2 answers
How one can dynamic_cast from std::exception to std::nested_exception?
I've just seen a code containing dynamic_cast from std::exception to std::nested_exception, for instance,
try {
std::throw_with_nested(std::runtime_error("error"));
} catch (std::exception &e) {
auto &nested =…

slyx
- 2,063
- 1
- 19
- 28
3
votes
1 answer
How does this implementation of chaining exceptions work?
I previously asked a question about how to chaining exceptions in C++, and one of the answers provided a nifty solution to how it can be done. The problem is that I don't understand the code, and trying to have this kind of discussion in the…

gablin
- 4,678
- 6
- 33
- 47
2
votes
1 answer
Cannot Cast float to int in Error Handling/Validation Function
I have a function to validate some user input (val) that begins as string input. I want the input to end up in integer format but I don't want to strip a number like 4.2 to make it 4. Instead, I want to throw an error and explain the problem to the…

Eoin
- 45
- 5
2
votes
1 answer
Junit5: Expect nested exception
How does JUnit 5 allow to check for a nested exception? I'm looking for something similar to what could be done in JUnit 4 with the help of a @org.junit.Rule, as shown in the following snippet:
class MyTest {
@Rule
public ExpectedException…

Markus Pscheidt
- 6,853
- 5
- 55
- 76
2
votes
0 answers
How to do Distributed testing using JMeter in Azure VMs over firewall
I am trying to do distributed testing using JMeter over Azure VMs behind the firewall using the conventional ways defined in most of the articles. I have tried all the possible options defined in the following site and some other websites. I tried…

S Singha
- 41
- 1
- 6
2
votes
2 answers
Class path issue: NoClassDefException :
Here's the issue,
i have this one project X that uses another project Y's services. Y was exported as jar file using eclipse and added to the project X build path. it so happens that the class that the spring loads "classService" in X can't load…

Vik2r
- 145
- 1
- 2
- 7
1
vote
1 answer
std::throw_with_nested() on out of memory condition calls std::terminate()
I've been strong exception guarantee testing a class, especially on what happens on an out of memory condition, by randomly making malloc() return nullptr. It uses nested exceptions.
Let's say I have the following code:
static…

小太郎
- 5,510
- 6
- 37
- 48
1
vote
2 answers
How to catch nested SMTPAddressFailedException using Spring mail API
I am trying to send email to user provided email id and I am getting below :
org.springframework.mail.MailSendException:
Failed messages: javax.mail.SendFailedException: Invalid Addresses;
nested exception…

sunny_dev
- 765
- 3
- 15
- 34