简体   繁体   English

我怎么知道我的try-catch块中抛出了什么错误?

[英]How do I know what errors are being thrown in my try-catch blocks?

When I'm building my programs, I have a number of try-catch blocks and when they throw errors, I seem to have trouble seeing what caused the error - I've tried looking at the stack-trace but I always end up commenting out the error handling and re-running. 当我正在构建程序时,我有许多try-catch块,当它们抛出错误时,我似乎很难看到导致错误的原因 - 我已经尝试查看堆栈跟踪但我总是最终评论退出错误处理并重新运行。

Is there a better way? 有没有更好的办法? (I'm sure there must be ...) (我敢肯定必须......)

If every time I have to comment out the bits of my try-catch to figure out why it was throwing it seems like I should be able to look at the stack-trace or something. 如果每次我必须注释掉我的try-catch的一些部分来弄清楚它为什么抛出它似乎我应该能够查看堆栈跟踪或其他东西。 Sorry if it's a simple question but it should have a simple answer ... 对不起,如果这是一个简单的问题,但它应该有一个简单的答案......

In Visual Studio, do the follow steps: 在Visual Studio中,执行以下步骤:

  • Menu [Debug] 菜单[调试]
  • Option [Exceptions...] 选项[例外......]
  • On the right of [Common Language Runtime Exceptions], check the box under [Thrown]. 在[Common Language Runtime Exceptions]的右侧,选中[Thrown]下的框。

Now your application will always stop (as if it is a breakpoint) at the line where an exception is thrown. 现在,您的应用程序将始终在抛出异常的行停止(就好像它是一个断点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM