查找功能名称 [英] Find Name of Function

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

问题描述

如何找到当前正在执行的函数的名称。


例如,假设我有以下功能


void Blah(int?y){

int z;

try {

z = y;

}

catch(Exception ex){

throw ex

}

}

哪个如果y为null(Nullable)将抛出异常。

我正在编写一个类来记录SQL数据库的任何异常,一列

表示当前的名称函数哪里有异常

生成会非常方便。

因此,我会记录它,而不是抛出异常,并处理

优雅地例外。


如果没有

调试符号编译的二进制文件,不确定是否可以这样做。那么有人关心开导我吗?

How can I find the name of the current function being executed.

For example, lets say I have the following function

void Blah(int? y){
int z;
try {
z = y;
}
catch(Exception ex){
throw ex
}
}
Which will throw an exception if y is null(Nullable).
I am writing a class to log any exceptions to a SQL database, a column
indicating the name of the current function where the exception was
generated would be very handy.
So instead of throwing the exception, I would log it, and handle the
exception gracefully.

Not to sure if this can be done, on binaries not compiled without
debugging symbols. So does anyone care to enlighten me?

推荐答案

Mick Walker写道:
Mick Walker wrote:

如何我可以找到正在执行的当前函数的名称。


例如,假设我有以下函数


void Blah(int ?y){

int z;

尝试{

z = y;

}

catch(Exception ex){

throw ex

}

}

哪会抛出异常如果y为null(Nullable)。

我正在编写一个类来记录SQL数据库的任何异常,一列

表示当前函数的名称,其中异常是生成的
会非常方便。

因此,我会记录它,而不是抛出异常,并优雅地处理

异常。 br />

不确定是否可以这样做,对于没有编译的二进制文件没有

debugging symb醇。那么有人关心开导我吗?
How can I find the name of the current function being executed.

For example, lets say I have the following function

void Blah(int? y){
int z;
try {
z = y;
}
catch(Exception ex){
throw ex
}
}
Which will throw an exception if y is null(Nullable).
I am writing a class to log any exceptions to a SQL database, a column
indicating the name of the current function where the exception was
generated would be very handy.
So instead of throwing the exception, I would log it, and handle the
exception gracefully.

Not to sure if this can be done, on binaries not compiled without
debugging symbols. So does anyone care to enlighten me?



我的坏...


void Blah(int?y){

int z;

尝试{

z =(int)y;

}

catch(Exception ex){< br $> b $ b抛出

}

}

My bad...

void Blah(int? y){
int z;
try {
z = (int)y;
}
catch(Exception ex){
throw ex
}
}


尝试使用Google搜索,你会发现许多建议:


< http://www.google.com/search?source=...23+get+name+of

+当前+功能>

Try using Google search and you will find many suggestions:

<http://www.google.com/search?source=...23+get+name+of
+current+function>


Roger Stewart写道:
Roger Stewart wrote:

尝试使用Google搜索和你会发现很多建议:


< http://www.google.com/search?source=...23+get+name+of

+当前+功能>
Try using Google search and you will find many suggestions:

<http://www.google.com/search?source=...23+get+name+of
+current+function>



在发布之前这样做了ERE。我实际上找到了

MethodBase.GetCurrentMethod()。Name.ToString()


我之所以没提到它的原因是因为我想找到一般

如何做到这一点的共识。

Did that before posting here. I actually found
MethodBase.GetCurrentMethod().Name.ToString()

The reason I didn''t mention it was because I wanted to find the general
consensus on how to do it.


这篇关于查找功能名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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