1.2*_*tts 7 visual-studio visual-studio-mac
当我调试项目并遇到运行时错误时,调试器会停止在主线上,而不是错误线上。
使用AppKit;
namespace Project {
static class MainClass {
static void Main(string[] args) {
NSApplication.Init();
NSApplication.Main(args); // breaks here
}
}
}
Run Code Online (Sandbox Code Playgroud)
而不是错误行:
if (isTrue) {
button.Title = "Title"; // Object reference not set to an instance of an object
}
Run Code Online (Sandbox Code Playgroud)
有没有办法改变它,使其在有错误的行上中断?
然而,下次它不会被选中:
这在 Visual Studio for Mac 中对我有用:
转到主菜单View -> Debug Windows -> Breakpoints
单击New Exception Catchpoint
按钮(或Breakpoint
代替Catchpoint)
保持选项不变,即:
a)断点操作=Pause the program
b)何时采取行动= When an exception is thrown
( "System.Exception" ; 包括子类 = true
)
单击按钮Create
确认
就是这样。启动项目(主菜单Run -> Start Debugging
或单击工具栏中的播放按钮)并享受捕获错误的乐趣
那要看。当然,最简单的方法(如果您知道您正在查找特定错误)是在异常窗口中启用(检查)相应的异常(调试->Windows->异常设置->公共语言异常)。由于 NRE 在运行时并不是您所期望的,因此这对于这些来说非常有效。
如果异常未处理且位于主线程上,您通常想要的是默认行为。如果异常发生在任务或异步方法中,事情确实会变得有点难看,因为异常首先被包装到一个AggregateException
稍后在等待任务时抛出到主线程的异常。
当您遇到这种不良行为时,调用堆栈中是否仍然具有正确的位置?如果异常发生在不同的模块中,您可能还需要禁用“仅我的代码”。
归档时间: |
|
查看次数: |
3435 次 |
最近记录: |