StackTrace行号 [英] StackTrace Line Numbers

查看:88
本文介绍了StackTrace行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑此代码


公共类MyClass {

public bool MyMethod1(){

return false;

}

public bool MyMethod2(){

int x = 0,y = 1 / x;

返回false ;

}

}

如果MyMethod2中发生异常,堆栈跟踪将包含

行相对于文件开头的数字(在我们的例子中为第6行)。

无论如何都要改变那种行为,并在方法声明中显示行号相对

(第1行)?

我们使用CodeDOM来动态生成代码,如果发生任何异常

在每种方法中,获取行号将更加相关

相对于每种方法。

谢谢!

Please consider this code

public class MyClass{
public bool MyMethod1(){
return false;
}
public bool MyMethod2(){
int x=0,y=1/x;
return false;
}
}
If an exception occurs within MyMethod2 the stack trace is going to contain
the line numbers relative to the beginning of the file (in our case line 6).
Is there anyway to change that behavior and show the line numbers relative
to the method declaration (line 1)?
We use CodeDOM to generate the code on a fly and if any exception occurs
within each method it would be much more relevant to get the line numbers
relative to each method.
Thanks!

推荐答案

Vlad< RE *** ************@comcast.net>写道:
Vlad <RE***************@comcast.net> wrote:
请考虑此代码

公共类MyClass {
public bool MyMethod1(){
return false;
}
public bool MyMethod2(){
int x = 0,y = 1 / x;
返回false;
}
}如果MyMethod2中发生异常堆栈跟踪将包含相对于文件开头的行号(在我们的示例中为第6行)。
无论如何都要改变该行为并显示行号相对
方法声明(第1行)?
我们使用CodeDOM来动态生成代码,如果在每种方法中发生任何异常,那么获取行号将更加相关
相对于每种方法。
Please consider this code

public class MyClass{
public bool MyMethod1(){
return false;
}
public bool MyMethod2(){
int x=0,y=1/x;
return false;
}
}
If an exception occurs within MyMethod2 the stack trace is going to contain
the line numbers relative to the beginning of the file (in our case line 6).
Is there anyway to change that behavior and show the line numbers relative
to the method declaration (line 1)?
We use CodeDOM to generate the code on a fly and if any exception occurs
within each method it would be much more relevant to get the line numbers
relative to each method.




是 - 您可以使用#line指令,例如


#line 1

-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



Yes - you can use the #line directive, eg

#line 1

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



嗨Vlad,


感谢您在社区发帖!我的名字是杰弗里,我将在这个问题上帮助你。


=============== =============================

是的,正如Jon所说,你可以使用Line指令来为源代码指定任何行

编号。


有关Line指令的更多信息,请参阅:
http://msdn.microsoft.com/ library / de ... us / csref / html /

vclrfLine.asp


希望它有所帮助,

祝你好运,

Jeffrey Tan

微软在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有授予任何权利。


Hi Vlad,

Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.

============================================
Yes, just as Jon said, you can use Line directives to specify any line
number for your source code.

For more information about Line directives, please refer to:
http://msdn.microsoft.com/library/de...us/csref/html/
vclrfLine.asp

Hope it helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


非常感谢!

这正是我所需要的

Vlad

" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ msnews.microsoft.c om ...
Thanks a lot!
That''s exactly what I needed
Vlad
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Vlad< RE *************** @ comcast.net>写道:
Vlad <RE***************@comcast.net> wrote:
请考虑此代码

公共类MyClass {
public bool MyMethod1(){
return false;
}
public bool MyMethod2(){
int x = 0,y = 1 / x;
返回false;
}
}如果MyMethod2中发生异常堆栈跟踪将转到
包含相对于文件开头的行号(在我们的例子中为
6行)。有没有改变那种行为,并显示相对于方法声明(第1行)的行号

我们使用CodeDOM动态生成代码,如果发生任何异常
每种方法相对于每种方法得到
数字更为相关。
Please consider this code

public class MyClass{
public bool MyMethod1(){
return false;
}
public bool MyMethod2(){
int x=0,y=1/x;
return false;
}
}
If an exception occurs within MyMethod2 the stack trace is going to contain the line numbers relative to the beginning of the file (in our case line 6). Is there anyway to change that behavior and show the line numbers relative to the method declaration (line 1)?
We use CodeDOM to generate the code on a fly and if any exception occurs
within each method it would be much more relevant to get the line numbers relative to each method.



是的 - 你可以使用#line指令,例如

#line 1

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该群组,请不要给我发邮件



Yes - you can use the #line directive, eg

#line 1

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



这篇关于StackTrace行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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