C#中的异常中的异常处理

Shr*_*oid 5 c# exception-handling exception

我知道这可能有点奇怪,但怀疑是一个疑问...在下列情况下会发生什么......

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??
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

Rob*_*boy 4

我个人会用另一个 try\catch 语句来包装写入事件日志的调用。

然而,最终这取决于您的规格。如果将故障写入事件日志对于系统至关重要,那么您应该允许抛出它。但是,根据您的示例,我怀疑这是否是您想要做的。

  • +1。顺便说一句:“哟狗,我听说你喜欢捕捉异常,所以我在你的 try-catch 中放了一个 try-catch,这样你就可以一边捕捉一边捕捉。” :) (6认同)