Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何接受在catch块中抛出的异常?_C#_.net_Exception Handling - Fatal编程技术网

C# 如何接受在catch块中抛出的异常?

C# 如何接受在catch块中抛出的异常?,c#,.net,exception-handling,C#,.net,Exception Handling,下面是我的一些错误日志代码。当我的应用程序内部发生异常时,我会将其记录到数据库中。如果该数据库已关闭或出现其他问题,我会尝试将其记录在事件查看器中 如果事件查看器写入也因某种原因失败,会发生什么情况?我如何放弃或接受这个新的例外 void SaveLog(string accountId, Exception ex, Category category, Priority priority) { try { using (var connection = new

下面是我的一些错误日志代码。当我的应用程序内部发生异常时,我会将其记录到数据库中。如果该数据库已关闭或出现其他问题,我会尝试将其记录在事件查看器中

如果事件查看器写入也因某种原因失败,会发生什么情况?我如何放弃或接受这个新的例外

void SaveLog(string accountId, Exception ex, Category category, Priority priority)
{
    try
    {
        using (var connection = new SqlConnection(…))
        {
            connection.Open();
            command.ExecuteNonQuery();
        }
    }
    catch (Exception exception)
    {
        // exception while logging!   
        using (var eventLog = new EventLog { Source = "tis" })
        {
            eventLog.WriteEntry(
                exception.Message + Environment.NewLine + 
                exception.StackTrace,
                EventLogEntryType.Error);
        }
    }
}

挡块没有什么特别的。你会如何在一个拦网之外做这件事?在挡块内以同样的方式操作。
try {
    // ...
}
catch (Exception exception) {
    try {
        // Attempt to write to event log.
    }
    catch {
    }
}