C # Best way to ignore exception

Possible duplicate:
Ignore exception in C #

Sometimes in rare cases, you really want to just ignore the exception. What is the best way to do this? my approach is an exception, but do nothing. others?

try { blah } catch (Exception e) { <nothing here> } 
+4
source share
3 answers

If you are going to just catch, not handle the exception and ignore it, you can simplify what you have.

 try { // code } catch { } 

Above for any exception, if you want to ignore any exception, but let others bubble up, you can do it

 try { // code } catch (SpecificException) { } 

If you ignore exceptions like this, it is best to include some comment in the catch block as to why you are ignoring such an exception.

+13
source
 try { DoBlah(); } catch { } 
+3
source

It could be something like this

 try { //blah } catch{} 

If you want to ignore a specific exception

 try { //blah }catch(YourException){} 
+3
source

All Articles