WCF 故障异常行号
WCF Fault Exception Line Number
我试图在 WCF 服务中获取完整的异常详细信息,但是,我没有获取发生异常的行号。
try
{
...
}
catch (Exception e)
{
throw new FaultException(e.ToString());
}
我尝试了各种方法,例如返回 e.StackTrace
等,但没有成功。请帮助我如何获取发生异常的行号。
使用:
catch (Exception e)
{
// Get stack trace for the exception with source file information
var st = new StackTrace(e, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
}
它会为您提供所需的信息。
此代码将提供带有行号的堆栈跟踪
try
{
///...
}
catch (Exception e)
{
throw new FaultException<Exception>(ex, ex.Message);
}
我会说你必须删除整个 try
catch
块:
更好的方法是将其注释掉:
//try
//{
Code.DoSomething(); //of course this code line is only a example and not working
/*the code inside the try block should now stop on the line, where the error appears*/
// might look like this: http://www.homeandlearn.co.uk/csharp/images/conditional_logic/Error_Parse.gif
//}
//catch (Exception e)
//{
//throw new FaultException(e.ToString());
//}
你应该得到一些像这样的东西:(我根据这个在 google 上找到的唯一图像)
我试图在 WCF 服务中获取完整的异常详细信息,但是,我没有获取发生异常的行号。
try
{
...
}
catch (Exception e)
{
throw new FaultException(e.ToString());
}
我尝试了各种方法,例如返回 e.StackTrace
等,但没有成功。请帮助我如何获取发生异常的行号。
使用:
catch (Exception e)
{
// Get stack trace for the exception with source file information
var st = new StackTrace(e, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
}
它会为您提供所需的信息。
此代码将提供带有行号的堆栈跟踪
try
{
///...
}
catch (Exception e)
{
throw new FaultException<Exception>(ex, ex.Message);
}
我会说你必须删除整个 try
catch
块:
更好的方法是将其注释掉:
//try
//{
Code.DoSomething(); //of course this code line is only a example and not working
/*the code inside the try block should now stop on the line, where the error appears*/
// might look like this: http://www.homeandlearn.co.uk/csharp/images/conditional_logic/Error_Parse.gif
//}
//catch (Exception e)
//{
//throw new FaultException(e.ToString());
//}
你应该得到一些像这样的东西:(我根据这个在 google 上找到的唯一图像)