Jan 19, 2014 at 10:43am Jan 19, 2014 at 10:43am UTC
The program call myterminate and std::terminate..
why?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <exception>
void myterminate () {
std::cerr << "termninate called\n" ;
throw 0;
}
int main (void ) {
std::set_terminate(myterminate);
try
{
throw 'x' ;
}
catch (int ) { std::cerr << "caught int\n" ; }
system("pause" );
}
Last edited on Jan 19, 2014 at 10:43am Jan 19, 2014 at 10:43am UTC
Jan 19, 2014 at 10:52am Jan 19, 2014 at 10:52am UTC
You are throwing a char and and there is only a catch for an int.
This works.
http://ideone.com/PdHHuo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <exception>
void myterminate () {
std::cerr << "termninate called\n" ;
throw 0;
}
int main (void ) {
std::set_terminate(myterminate);
try
{
throw 'x' ;
}
catch (char ) { std::cerr << "caught char\n" ; }
}
EDIT: Link
Last edited on Jan 19, 2014 at 10:54am Jan 19, 2014 at 10:54am UTC
Jan 19, 2014 at 11:20am Jan 19, 2014 at 11:20am UTC
Ah ok, while unexpected returns to the caller .. ok thank you so much now I understand =)