自定义异常:在调用基本构造函数之前自定义消息
Custom Exception: customize message before call the base constructor
我定义了这个自定义异常
public class ThirdPartyServiceException : System.Exception
{
public ThirdPartyServiceException(string message, Exception innerException): base(message, innerException)
{ }
}
很好,但现在我想在调用基本构造函数之前自定义异常消息。类似于:
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)
}
}
但是我不能用这种方式调用基础构造函数。那我该怎么办?
覆盖 Message
属性。
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)
{
}
}
我定义了这个自定义异常
public class ThirdPartyServiceException : System.Exception
{
public ThirdPartyServiceException(string message, Exception innerException): base(message, innerException)
{ }
}
很好,但现在我想在调用基本构造函数之前自定义异常消息。类似于:
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)
}
}
但是我不能用这种方式调用基础构造函数。那我该怎么办?
覆盖 Message
属性。
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)
{
}
}