我需要重新抛出被捕获并存储在其他地方的异常没有丢失有关何时第一次捕获/存储异常的堆栈跟踪信息。我的代码看起来是这样的:在Silverlight中重新抛出异常时保留堆栈跟踪
public void Test()
{
int someParameter = 12;
ExecuteSomeAsyncMethod(someParameter, CallbackMethod);
}
public void CallbackMethod(object result, Exception error)
{
//Check for exceptions that were previously caught and passed to us
if(error != null)
//Throwing like this will lose the stack trace already in Exception
//We'd like to be able to rethrow it without overwriting the stack trace
throw error;
//Success case: Process 'result'...etc...
}
我已经看到了使用反射(例如here和here)对这个问题的解决方案,或者使用序列化(例如here),但这些都不将在Silverlight为我工作(不允许使用私人反射,并且Silverlight中不存在序列化方法中使用的类/方法)。
有什么办法来保存在Silverlight中工作的堆栈跟踪?
这看起来像我现在唯一的选择。不幸的是,这可能会干扰现有的代码,比如“catch(SpecificExceptionClass)”,否则它会检查异常类型。理想情况下,我希望尽可能避免包装Exception,因为我不希望消费者必须开始检查InnerExceptions是否存在“真实”异常。 – 2010-11-29 23:26:05