I have a CustomException
class, that is a wrapper on top of Exception
class. This is the main class that i use when i handle Exceptions.
public class CustomException : Exception
{
public string ErrorMessage { get; private set; }
public HttpStatusCode HttpStatusCode { get; private set; }
public CustomException(string errorMessage)
: this(errorMessage, HttpStatusCode.InternalServerError)
{ }
public CustomException(string message, HttpStatusCode httpStatusCode)
{
ErrorMessage = message;
HttpStatusCode = httpStatusCode;
}
}
When i want to throw an exception, i use throw CustomException()
method.
However, i want to create some wrappers on top of this CustomException() as well, for example:
public class ApplicationNotFoundException : Exception
{
public ApplicationNotFoundException(Application application)
{
string message = string.Format(@"Application ""{0}"" was not found", application.ApplicationName);
throw new CustomException(message, HttpStatusCode.NotFound);
}
}
And i throw exception line this: throw new ApplicationNotFoundException(application)
Basically i am throwing an Exception from another Exception.
Is this approach bad?