Tuesday, January 31, 2012

Deriving the Exceptions from Exception class or ApplicationException class

I was doing a code review today and chanced to look upon msdn to get some guidance around how to work with Exceptions. 
Thankfully the guideline around the application specific exceptions derving from ApplicationException has changed and now it is advised that application developers should derive their exceptions from Exception class. 
The reason for that is fairly simple. If all application exceptions had to derive from ApplicationException class then it would have meant that something as simple as ArgumentException had to be reinvented. Because applications do have cases where the ArgumentException has to be thrown and in that case i would want to reuse the ArgumentException class provided by the framework. And this class is deriving from the Exception class and not ApplicationException class. So it simply was not working :)
For more details check Remarks section on this msdn page. 



~Abhishek


No comments: