some friends just finished the implementation of an app and they use Custom Exceptions. something that took my attention is that when a custom exception was raised they logged the exception in the code of the exception base class they implemented. so my question will be is this a good design approach?. my thinking is that a logging helper is more usable
public class BaseCustomException: System.Exception
{
public BaseCustomException()
{
TightlyCoupledClass.Log(this);
}
}
I understand their thinking in putting this into place so that they can assure that logging happens whenever an exception of CustomException is thrown; however, this is definitely smelly code.
An exception should be used just for exceptions and the code that executes the code that could cause a CustomException to be thrown should be able to decide what to do with that exception and whether or not to log it... because the logging should be specific to the scenario in which it was caused.
A side note, custom exceptions should inherit from ApplicationException as a root so that you can tell if the exception is custom to your business libraries or from the .NET framework itself.
--CORRECTION-- I just found this post that I was not aware of that essentially renders using ApplicationException useless.