【发布时间】:2011-01-04 20:48:40
【问题描述】:
我的代码如下所示。
try
{
_productRepo.GetAllProductCategories();
}
catch (Exception ex)
{
//Do Something
}
我需要一种显示方法名称的方法,假设在上述情况下,如果在 GetAllProductCategories() 方法中引发任何异常,我需要获取此方法名称,即“GetAllProductCategories()”作为我的结果。谁能建议我如何做到这一点?
【问题讨论】:
-
简单的答案?它是调用堆栈顶部的方法。这是在异常发生之前最近调用的方法。 :)
-
我通过检查这个答案解决了stackoverflow.com/questions/27997276/…
标签: c# exception-handling try-catch