Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# and catching exceptions

Tags:

c#

exception

Is it good practice to append a general exception catch when handling exceptions. an example may make this question clearer

try{
 // do something
}catch(spomespecificException1 ex){
 //logging and other stuff
}catch(spomespecificException2 ex){
 //logging and other stuff
}catch(Exception ex){
 //logging and other stuff
}

should i append the exception catch to the stack

like image 441
Richard Banks Avatar asked Dec 16 '22 08:12

Richard Banks


1 Answers

You shouldn't be catching those exceptions at all, in general. Don't catch exceptions that you don't actually know how to handle.

"Handle" means fix. If you can't fix the problem, or if you can't add additional information, then don't catch the exception.

like image 132
John Saunders Avatar answered Jan 02 '23 11:01

John Saunders