我需要重新拋出被捕獲並存儲在其他地方的異常沒有丟失有關何時第一次捕獲/存儲異常的堆棧跟蹤信息。我的代碼看起來是這樣的:在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