1.
Exceptions are silly. Just do a:
try {
/* do stuff */
} catch {}
and you will never get any exceptions. Do this for each block of code. Randomly let some lines of code outside the try catch block to appear that you carefully considered which blocks of code to handle and which not.
2.
If the users report they receive an error about some weird exception, don't spend too much time to identify the reason the exception appear. Just find the place where the exception is thrown and do a:
try {
/* stuff that caused the exception*/ }
catch (WeirdException) {}
Make absolutely sure you do not log the exception. Also very important, don't write any meaningful comment about the reason the exception is catch.
3.
Catch exceptions and throw them again without any change:
try {
/* do stuff */
} catch (Exception ex) {
throw ex;
}
This way you can not be accused that you didn't handle exceptions. The loosing of the exception stack trace is an added bonus.
4.
Put a lot of exception handling and make sure it is intricate with the code logic:
Service s;
try {
s = new Service();
if (s.IsOnline) {
try {
s.IsOnline = false;
} catch (Exception ex2) {
s.Link = s.DefaultlLink;
}
} else {
try {
s.ResetDefaultLink();
} catch (Exception ex3) {
s.IsOnline = true;
}
}
} catch(Exception ex1) {
s = new Service(true);
s.IsOnline = s.Link == s.DefaultLink ? true : false;
}
Anyone who looks over this code will be amazed to see the great care you took for exception handling. Do not add any comment as this would clutter the code even more than already is. No one will understand a thing of that code, nor even you, but this is expected as everyone knows exception handling is hard to code.
5.
Make your own exception class and use it every time to re-throw exceptions:
public class MyApplicationException : Exception {
public MyApplicationException(string m) : base(m) {
}
}
try {
/* do stuff */
} catch (Exception ex) {
throw new MyApplicationException("Error message here.");
}
Make sure the error message is as unintelligible or as useless as possible. "An error occured" is a good candidate and should be amoung your favorites. Also very important is to make sure you do not include the original exception as inner exception.