-
November 30th, 2010, 02:49 AM
#1
Unexpected Output
Function funExceptionHandler is not getting called though exception is thrown
Why?
Code:
#include <iostream>
#include <exception>
using namespace std;
void funExceptionHandler () {
cerr << "unexpected handler called\n";
}
void fun () throw (int) {
throw 1.11; // throws double (not in exception-specification)
}
int main (void) {
set_unexpected (funExceptionHandler);
try {
fun();
}
catch (double) { cerr << "caught double\n"; }
catch (...) { cerr << "caught other exception (non-compliant compiler?)\n"; }
return 0;
}
-
November 30th, 2010, 05:02 AM
#2
Re: Unexpected Output
When I compile the example (VC2008) I get this warning.
warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
November 30th, 2010, 06:30 AM
#3
Re: Unexpected Output
Didn't I answer this yesterday?
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|