我知道这可能有点奇怪,但怀疑终究是怀疑……在以下情况下会发生什么.
private void SendMail()
{
try
{
//i try to send a mail and it throws an exception
}
catch(Exception ex)
{
//so i will handle that exception over here
//and since an exception occurred while sending a mail
//i will log an event with the eventlog
//All i want to know is what if an exception occurs here
//while writing the error log, how should i handle it??
}
}谢谢。
发布于 2010-05-18 17:20:48
我会亲自用另一个try\catch语句包装写入事件日志的调用。
但是,这最终取决于您的规范是什么。如果将失败写入事件日志对系统来说很重要,那么您应该允许抛出它。但是,根据您的示例,我怀疑这是您想要做的事情。
发布于 2010-05-18 17:41:39
您可以简单地在错误日志记录方法中捕获错误。然而,我个人不会这么做,因为错误日志记录是你的应用程序根本无法工作的标志。
private void SendMail()
{
try
{
//i try to send a mail and it throws an exception
}
catch(Exception ex)
{
WriteToLog();
}
}
private void WriteToLog()
{
try
{
// Write to the Log
}
catch(Exception ex)
{
// Error Will Robinson
// You should probably make this error catching specialized instead of pokeman error handling
}
}发布于 2010-05-18 17:28:54
只有在try-catch块中才能捕获每个异常。您可以嵌套try-catch,但通常不是一个好主意。
https://stackoverflow.com/questions/2855836
复制相似问题