cap*_*gon 1 .net c# exception-handling
我想捕获一个异常,告诉我是否故意抛出错误或其他类似运行时错误(对象不是对象的实例).
try
{
    throw new Exception("throw this", "these can be many possible values");
}
catch (System.Exception ex)
{
    if (IThrew) // <--- how can i tell if i threw or not?
    {
        exReport = "one thing"; // <--- Should go in here in this example.
    }
    else
    {
        exReport = "another thing";
    }
    throw new FaultException<ExceptionReport>(exReport, new FaultReason(ex.Message), new FaultCode("Receiver"));
}
澄清:
我需要记录所有异常然后在最后将它们显示在异常报告中(例外数组).这是我需要遵循的架构的一部分.(所以请不要让我以另一种方式去做).
我把它全部工作得很好它输出如下:
...
<soap:Detail>
<ows:ExceptionReport>
 <Exception exceptionCode="…" locator="…">
  <ExceptionText>…</ExceptionText>
 </Exception>
 <Exception exceptionCode="…" locator="…">
  <ExceptionText>…</ExceptionText>
 </Exception>
</ows:ExceptionReport>
</soap:Detail>
...
问题是,当我的ExceptionReport中已经有一些错误时,就会发生运行时错误.
但我已经意识到我对此有错误的方法......正如加里所说......我不应该使用例外作为流量控制.