Reputation: 5274
In my C# application, I am catching exceptions of type SystemException
, yet Visual Studio 2015 breaks when the exception is raised:
As you can see in the screen-capture above, I am intentionally releasing an ISupportInitialize
lock early, before certain objects are initialized. I am expecting the exception, and have a catch block.
Also, the exceptions I am interested in are not listed in the exception settings window; i.e. they are not checked to go into the break mode.
And although the dialog shows that "Break when this exception is thrown" is unchecked, and yet, the application still goes into break mode.
EDIT:
Stack trace requested by SLaks:
PresentationCore.dll!System.Windows.Media.GlyphRun.CheckInitialized() Unknown
PresentationCore.dll!System.Windows.Media.GlyphRun.ComputeInkBoundingBox() Unknown
PresentationCore.dll!System.Windows.Media.BoundsDrawingContextWalker.DrawGlyphRun(System.Windows.Media.Brush foregroundBrush, System.Windows.Media.GlyphRun glyphRun) Unknown
PresentationCore.dll!System.Windows.Media.RenderData.DrawingContextWalk(System.Windows.Media.DrawingContextWalker ctx) Unknown
PresentationCore.dll!System.Windows.Media.RenderData.GetContentBounds(System.Windows.Media.BoundsDrawingContextWalker ctx) Unknown
PresentationCore.dll!System.Windows.UIElement.GetHitTestBounds() Unknown
PresentationCore.dll!System.Windows.Media.Visual.PrecomputeContent() Unknown
PresentationCore.dll!System.Windows.Media.Visual.PrecomputeRecursive(out System.Windows.Rect bboxSubgraph) Unknown
PresentationCore.dll!System.Windows.Media.Visual.PrecomputeRecursive(out System.Windows.Rect bboxSubgraph) Unknown
PresentationCore.dll!System.Windows.Media.Visual.PrecomputeRecursive(out System.Windows.Rect bboxSubgraph) Unknown
PresentationCore.dll!System.Windows.Media.Visual.PrecomputeRecursive(out System.Windows.Rect bboxSubgraph) Unknown
PresentationCore.dll!System.Windows.Media.Visual.PrecomputeRecursive(out System.Windows.Rect bboxSubgraph) Unknown
PresentationCore.dll!System.Windows.Media.Visual.PrecomputeRecursive(out System.Windows.Rect bboxSubgraph) Unknown
PresentationCore.dll!System.Windows.Media.Visual.PrecomputeRecursive(out System.Windows.Rect bboxSubgraph) Unknown
PresentationCore.dll!System.Windows.Media.Visual.Precompute() Unknown
PresentationCore.dll!System.Windows.Media.CompositionTarget.System.Windows.Media.ICompositionTarget.Render(bool inResize, System.Windows.Media.Composition.DUCE.Channel channel) Unknown
PresentationCore.dll!System.Windows.Media.MediaContext.Render(System.Windows.Media.ICompositionTarget resizedCompositionTarget) Unknown
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget) Unknown
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) Unknown
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) Unknown
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Unknown
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Unknown
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) Unknown
PresentationFramework.dll!System.Windows.Application.Run() Unknown
FargoApp.exe!FargoApp.App.Main() Unknown
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) Unknown
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() Unknown
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) Unknown
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Unknown
Upvotes: 0
Views: 1119
Reputation: 2767
You can not catch the exception probably because it occurs in another thread. For such scenarios you can add an event handler to DispatcherUnhandledExceptiont event in your App.xaml.cs, like this:
DispatcherUnhandledException += (sender, args) =>
{
Console.WriteLine("Wild exception appeared!!!");
};
This way you can be sure that exceptions thrown by your applications but not handled will trigger this handler. Mor info here
Hope this helps!
Upvotes: 2