没有被捕获的例外

时间:2014-09-13 21:08:33

标签: c# .net asp.net-mvc exception-handling

在我的MVC 5应用程序中,我有这段代码:

try
{
    var inputFile = new MediaFile { Filename = videoPath };
    var outputFile = new MediaFile { Filename = Config.ThumbPath };

    using (var engine = new Engine())
    {
        engine.GetMetadata(inputFile);

        if (inputFile.Metadata != null && inputFile.Metadata.Duration.TotalSeconds > 0)
        {
            var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(inputFile.Metadata.Duration.TotalSeconds / 2) };
            engine.GetThumbnail(inputFile, outputFile, options);

            byte[] imageArray = System.IO.File.ReadAllBytes(Config.ThumbPath);
            base64ImageRepresentation = "data:image/jpeg;base64," + Convert.ToBase64String(imageArray);
        }
    }

}
catch (Exception ex)
{ 
     if (!EventLog.SourceExists("MYAPP"))
           EventLog.CreateEventSource("MYAPP", "Application");

     EventLog.WriteEntry("MYAPP", "CACHED: " + ex.Message);
     EventLog.WriteEntry("MYAPP", "CACHED: " + ex.Message,EventLogEntryType.Warning,234);
}

engine.GetMetadata(inputFile);会抛出这个:

  
    

未处理的类型' System.FormatException'发生在mscorlib.dll

  

我在NuGet安装的名为MediaToolkit的库中。

为什么我的try catch没有捕获此异常?

它获取的文件已损坏,这就是为什么它会抛出错误,但如果发生这种情况,我只想继续下一个文件。但是,相反,应用程序停止。

事件日志中没有条目,但源ASP.NET有另一个条目。

An unhandled exception occurred and the process was terminated.

Application ID: /LM/W3SVC/2/ROOT

Process ID: 7364

Exception: System.FormatException

Message: Input string was not in a correct format.

StackTrace:    at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Convert.ToInt32(String value)
   at MediaToolkit.Util.RegexEngine.TestAudio(String data, EngineParameters engine)
   at MediaToolkit.Engine.<>c__DisplayClass9.<FFmpegEngine>b__5(Object sender, DataReceivedEventArgs received)
   at System.Diagnostics.Process.ErrorReadNotifyUser(String data)
   at System.Diagnostics.AsyncStreamReader.FlushMessageQueue()
   at System.Diagnostics.AsyncStreamReader.GetLinesFromStringBuilder()
   at System.Diagnostics.AsyncStreamReader.ReadBuffer(IAsyncResult ar)
   at System.IO.Stream.ReadWriteTask.InvokeAsyncCallback(Object completedTask)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.IO.Stream.ReadWriteTask.System.Threading.Tasks.ITaskCompletionAction.Invoke(Task completingTask)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean bUserDelegateExecuted)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

1 个答案:

答案 0 :(得分:1)

可能 Visual Studio配置为停止对每个生成的异常执行(甚至已处理)。你可以在Debug - &gt;中查看它。例外。检查公共语言运行时例外类别,投掷设置。如果选中此设置,VS将在每个生成的CLR Exception上停止执行,您只需按F5继续或关闭此设置。

有关详细信息,请访问MSDN