-
Exception handling
Hi! I just started using exception handling (never had chance before). What you guys think it is best:
Code:
try{
//code that throws Exception_1
//code that do not throws anything
//code that throws Exception_2
}
catch(Exception_1 e1){
//handle exceptions
}
catch(Exception_2 e2){
//handle exceptions
}
Or:
Code:
try{
//code that throws Exception_1
}
catch(Exception_1){
//handle exceptions
}
//code that do not throws anything
try{
//code that throws Exception_2
}
catch(Exception_2){
//handle exceptions
}
//handle exceptions
I think that, for large pieces of code, the second alternative is better. Do you agree? Also, I have a question, when you use catch(...) m how can you access the exception itself?Is there any global or method, or I must specify the parameter?
Thanks, as always.
-
Entirely depends on how you want your errors to be handled...
-
>What you guys think it is best
It's up to you. I could use either depending on how my code is otherwise structured.
>when you use catch(...) m how can you access the exception itself?
How do you know what the exception is? It could be an exception object derived from the standard exception, or it could be an int. You just don't know, so how can you expect to "access" it safely?
-