【发布时间】:2016-09-22 10:11:55
【问题描述】:
我正在使用 Visual Studio 2013 进行 C# 编程。我正在测试自定义异常,但异常消息出现在 throw 语句中(这是正确的),但我希望它出现在导致异常 1 的行中?我该怎么做?
class Abc
{
static void Main(String[] s)
{
Something(); // I want exception popup msg in this line
}
public static void something()
{
if(condition)
{
throw new SomeException(); // Exception popup message appear here
}
}
}
【问题讨论】:
-
“我希望它出现在导致第一个异常的行中”对我意味着什么,这非常不清楚。请尝试澄清,并理想地格式化您的代码下次更易读。 (也许您只需要在您的
Main方法中添加一个catch块?) -
你需要先定义这个“出现”这个词。我想你需要的是堆栈跟踪。 - msdn.microsoft.com/en-us/library/…
标签: c# exception runtime throw