我目前有一个
以下是堆栈跟踪的示例:
AppDomain.CurrentDomain.UnhandledException
处理程序,当应用程序崩溃时会发送给我一个堆栈跟踪。 这在大多数情况下都很好用,但当我在MVVM light viewmodel中遇到异常时,堆栈跟踪可能相当神秘,无法告诉我它们发生的位置。是否有一种简单的方法来包装我的viewmodels并在其中加入try catch语句,然后将一些更有用的信息注入到异常中并重新抛出它呢?以下是堆栈跟踪的示例:
在System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)处发生错误。 在System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)处发生错误。 在System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)处发生错误。 在System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)处发生错误。 在d:\GalaSoft\mydotnet\MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight (NET35)\Helpers\WeakAction.cs:line 269的GalaSoft.MvvmLight.Helpers.WeakAction.Execute()处发生错误。 在d:\GalaSoft\mydotnet\MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight (NET35)\Command\RelayCommand.cs:line 167的GalaSoft.MvvmLight.Command.RelayCommand.Execute(Object parameter)处发生错误。 在MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)处发生错误。 在System.Windows.Controls.Primitives.ButtonBase.OnClick()处发生错误。 在System.Windows.Controls.Button.OnClick()处发生错误。 在System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)处发生错误。 在System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)处发生错误。 在System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)处发生错误。 在System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)处发生错误。 在System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)处发生错误。 在System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)处发生错误。 在System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)处发生错误。 在System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)处发生错误。 在System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)处发生错误。 在System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)处发生错误。 在System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)处发生错误。 在System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)处发生错误。 在System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)处发生错误。 在System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)处发生错误。 在System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)处发生错误。 在System.Windows.Input.InputManager.ProcessStagingArea()处发生错误。 在System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)处发生错误。 在System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)处发生错误。 在System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)处发生错误。 在System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)处发生错误。 在System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)处发生错误。 在MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)处发生错误。 在MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)处发生错误。 在System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)处发生错误。 在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)处发生错误。 在System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)处发生错误。 在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)处发生错误。 在MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)处发生错误。 在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)处发生错误。 在System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)处发生错误。 在System.Windows.Threading.Dispatcher这是由于我的视图模型中的一个方法引发了
NotImplementedException
,该方法被包装在一个RelayCommand
中,以便我可以将一个按钮绑定到它上面。 我找不到任何指向该方法或视图模型名称的线索。