在 [0] 处重新抛出异常:

xha*_*fan 5 .net exception-handling stack-trace

我正在调查堆栈跟踪,我遇到了这个输出:

Server stack trace: 
   ...
   at MyProject.Data.Notifications.NotificationCache.InitialisedCache() in NotificationCache.cs: line 72
   at System.Lazy`1.CreateValue()

Exception rethrown at [0]: 
   at System.Lazy`1.get_Value()
   at MyProject.Data.Notifications.NotificationCache.AddItemToCache(NotificationDto dto) in NotificationCache.cs: line 82
bla bla bla
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下这Exception rethrown at [0]:意味着什么并展示一些如何复制它的简单场景吗?我试图通过 try/catch/throw、try/catch ex/throw ex 等复制它,但我不能。

Nic*_*oiu 5

Lazy<T>.CreateValue调用Exception.PrepForRemoting(),这是添加“在 [0] 处重新抛出异常”位的地方。就作者而言,这是一个有点奇怪的设计选择,但据推测,他将它用作获取“拆分”堆栈跟踪的一种方式,这将使您能够同时查看导致异常的代码和调用它的代码,尽管前者是通过委托调用的。