我不确定这是否可能。 (我认为它应该)。如果不按照以下方式抛出新的产品,是否有可能抓住客户的观点?在.NET中没有新投入的自定义异常
try
{
//Some logic which throws exception
}
catch (Exception)
{
throw new CustomException();
}
我想什么有如下:
try
{
//Some logic which throws exception
}
catch (CustomException)
{
// Handles the exception
}
我已经尝试了上面,但它不是直接抓我CustomException。我不得不做“throw new CustomException()
”这是不理想的。我究竟做错了什么?
我的自定义异常类看起来如下:
[Serializable]
public class CustomException : Exception
{
public CustomException()
: base() { }
public CustomException(string message)
: base(message) { }
public CustomException(string format, params object[] args)
: base(string.Format(format, args)) { }
public CustomException(string message, Exception innerException)
: base(message, innerException) { }
public CustomException(string format, Exception innerException, params object[] args)
: base(string.Format(format, args), innerException) { }
protected CustomException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
感谢,
问题是什么?你的第二个代码片段看起来很好。 – dlev 2013-05-13 08:13:25
对不起,只是编辑我的问题。 – daehaai 2013-05-13 08:14:54
代码是否抛出CustomException?或者是抛出一个不同的异常,你想变成一个CustomException?如果是后者,那么第二种方法就行不通了。 – dlev 2013-05-13 08:16:12