I had this straight in .Net 1.x: Derive custom exceptions from System.Exception, not from ApplicationException. The reasoning: you want your exception hierarchies to be wide and shallow, not deep, and that ApplicationException didn't add anything to Exception anyway. Jeffrey Richter notes that the difference between the two types of exceptions were originally to signal a CLR exception vs. one thrown from an application, but that this distinction was not followed consistently. Therefore, stick with System.Exception.
In .Net 2.0 we seem to have conflicting directives from Microsoft, which I am assuming is an error. The MTS 70-536 exam study materials point out (on p.24 of the training kit book) that we should derive from ApplicationException. Seems to fly in the face of the previous recommendation and based on the original .Net 1.x recommendations which were revised. The latest MSDN docs appear to recommend deriving custom exceptions from System.Exception.
I'm going to stick with System.Exception as the base class for custom exceptions. Don't know why I ended up bothered by this today.
No comments:
Post a Comment