Custom Exception: customize message before call the base constructor

230 views Asked by At

I defined this custom exception

public class ThirdPartyServiceException : System.Exception
{
    public ThirdPartyServiceException(string message, Exception innerException): base(message, innerException)
    { }
}

That's fine, but now I want customize the exception message before call the base constructor. Something like:

public class ThirdPartyServiceException : System.Exception
{
    public ThirdPartyServiceException(string code, string message, string description, Exception innerException)
    {
        base(string.format("Error: {0} - {1} | {2}", code, message, description), innerException) 
    }
}

But I can't call the base constructor in this way. So how I can do ?

2

There are 2 answers

0
ASh On BEST ANSWER
public class ThirdPartyServiceException : System.Exception
{
    public ThirdPartyServiceException(string code, string message, string description, Exception innerException)
    :base(string.format("Error: {0} - {1} | {2}", code, message, description), innerException) 
    {        
    }
}
1
Joe On

Override the Message property.