Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 显示当前函数的自定义错误消息_C# 4.0 - Fatal编程技术网

C# 4.0 显示当前函数的自定义错误消息

C# 4.0 显示当前函数的自定义错误消息,c#-4.0,C# 4.0,在我当前的错误处理中,我在messagebox中指定了表单、函数和错误消息,如下所示 try { //Some code here } catch(Exception ex) { MessageBox.Show("Form Title : " + this.Title + "\nFunction : CurrentFunction \nError : " + ex.Message); return; } 这对我来说是可行的,但我很好奇,我是否可以让这个过程变得更简单,生

在我当前的错误处理中,我在messagebox中指定了表单、函数和错误消息,如下所示

try
{
  //Some code here
}
catch(Exception ex)
{
     MessageBox.Show("Form Title : " + this.Title + "\nFunction : CurrentFunction \nError : " + ex.Message);
     return;
}
这对我来说是可行的,但我很好奇,我是否可以让这个过程变得更简单,生成函数名,而不是每次我想显示错误消息时都键入它

另外
我知道您可以包括stacktrace并查看最上面的几行,但我很好奇是否有更简洁的方式来显示函数

是的,如果您只需要当前函数(而不是调用函数),可以使用:


是的,如果您只需要当前函数(而不是调用函数),您可以使用:


这正是我想要的。谢谢你这正是我想要的。非常感谢。
string currentMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;