我想在WCF服务中获得完整的异常详细信息,但是,我没有收到发生异常的行号。WCF故障异常行号
try
{
...
}
catch (Exception e)
{
throw new FaultException(e.ToString());
}
我试过各种方式,如返回e.StackTrace
等没有运气。请帮助我如何获得发生异常的行号。
我想在WCF服务中获得完整的异常详细信息,但是,我没有收到发生异常的行号。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);
}
我试过这个,但我得到这个'现有连接被远程主机强行关闭' – SiD
我会说你必须删除整个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());
//}
你应该得到的东西像这样的:我在咕发现(只图像gle根据这个)
我已经试过了。它没有给出行号。它只给出像'试图除以零的信息。' – SiD
好吧,它已被编辑。 –