为什么未处理的异常不终止一个进程,而调试? [英] Why does an unhandled exception not terminate a process while debugging?

查看:443
本文介绍了为什么未处理的异常不终止一个进程,而调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题,我注意到前几次,我想知道背后的原因。如果运行在(Visual Studio 2008中)调试器下面的程序,调试器将继续打破了语句不管如何,往往你继续调试。你必须停止走出去调试。我希望,调试器打破一次,然后该程序终止,因为如果你没有调试器中运行该程序发生。是否有人知道一个很好的理由,这种行为?

 使用系统;

命名空间ExceptionTest
{
   静态内部类节目
   {
      静态内部无效的主要()
      {
         尝试
         {
            抛出新的异常();
         }
         赶上(例外的例外)
         {
            Console.WriteLine(exception.Message);

            //该debuger将永远超越
            // throw语句和终止
            //过程。为什么?
            扔;
         }
      }
   }
}
 

解决方案

步进比未处理的异常将终止该进程 - 它可能只是阻止您意外终止该进程,当你没有打算

如果异常是在其他地方(如在一个通用的外部try-catch块)来处理,那么你就可以跳过异常,调试器将带你到那里处理的地方。

This is a behavior I noticed several times before and I would like to know the reason behind that. If you run the following program under the (Visual Studio 2008) debugger, the debugger will keep breaking on the throw statement no matter how often you continue debugging. You have to stop debugging to get out there. I would expect that the debugger breaks once and then the process terminates as it happens if you run the program without the debugger. Is anybody aware of a good reason for this behavior?

using System;

namespace ExceptionTest
{
   static internal class Program
   {
      static internal void Main()
      {
         try
         {
            throw new Exception();
         }
         catch (Exception exception)
         {
            Console.WriteLine(exception.Message);

            // The debuger  will never go beyond
            // the throw statement and terminate
            // the process. Why?
            throw;
         }
      }
   }
}

解决方案

Stepping over the unhandled exception would terminate the process - its probably just to stop you from accidentally terminating the process when you didnt intend to.

If the exception is handled elsewhere (such as in a generic outer try-catch block) then you will be able to step over the exception and the debugger will take you to the place where it is handled.

这篇关于为什么未处理的异常不终止一个进程,而调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆