try
{
string s = null;
s.PadLeft(10);
}
catch (Exception ex)
{
// send exception to UI Thread so it can be handled by our global exception
// handler
Application.Current.Dispatcher.Invoke(DispatcherPriority.Send,
new Action<Exception>(e => { throw ex; }), ex);
}
如您所见,'throw ex' 会截断堆栈跟踪,我想使用
throw
而不是 throw ex
,但是我会得到以下错误信息:
如何使用 lambda 表达式抛出异常而不截断堆栈跟踪?在 catch 子句之外不允许使用没有参数的 throw 语句。