throw std::invalid_argument

M

mlt

In my code I use throw:

if (someCondition) {
std::cout << "time to throw!\n";
throw std::invalid_argument("very bad error!");
}


I then test for what happens when someCondition is true. "time to throw!"
gets printed but "very bad error!" is not printed. A box just pops up
saying:

Debug Error!

Program: ...

This application has requested the Runtime to terminate.....

(Press retry to debug application)


Should "very bad error!" not pop up somewhere?
 
R

red floyd

mlt said:
In my code I use throw:

if (someCondition) {
std::cout << "time to throw!\n";
throw std::invalid_argument("very bad error!");
}


I then test for what happens when someCondition is true. "time to throw!"
gets printed but "very bad error!" is not printed. A box just pops up
saying:

Debug Error!

Program: ...

This application has requested the Runtime to terminate.....

(Press retry to debug application)


Should "very bad error!" not pop up somewhere?

Why would you expect that? Are you catching invalid_argument and
sending something to cout? If you're not catching invalid_argument (or
its parent), then you're going to hit std::unexpected, which for your
compiler, apparently pops up the Runtime Termination dialog.
 
R

red floyd

Why would you expect that?  Are you catching invalid_argument and
sending something to cout?  If you're not catching invalid_argument (or
its parent), then you're going to hit std::unexpected, which for your
compiler, apparently pops up the Runtime Termination dialog.

That'll teach me to post while half asleep. If you don't catch your
exception, you'll go to std::terminate, not std::unexpected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top