0
Can a try catch block have multiple throw statements?
hey folks, I'm a little confused about the exception handling. Can a try/catch block only contain one throw statement? Can the catch statement handle more than one throws?? I'm wondering why the lesson only used one throw statement and not show how to handle multiple throws..? So is it possible?
1 Respuesta
+ 1
It can contain multiple throw Statements...
And, for sure, you can catch multiple of it..
try{
throw 567;
//throw std::range_error("Message");
}
catch(int e){
...
}
catch(const std::range_error& e){
...
}
catch(...){
...
}
This is the way to catch different exceptions in the order written...
catch(...) will catch all exceptions, but should be used very carefully...
Hope this helps :)