Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8012049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:12:40+00:00 2026-06-04T19:12:40+00:00

WPF provides a very convenient way to handle unexpected exceptions: I can just attach

  • 0

WPF provides a very convenient way to handle unexpected exceptions: I can just attach a handler to the Application.DispatcherUnhandledException event and all unhandled exceptions go this way:

Application.Current.DispatcherUnhandledException += (sender, e) => {
    // Show message, log exception, etc.
};

This works great for WPF application projects. Now, I have a library with WPF windows, which is called from a non-WPF application (it’s a legacy VBA app, and the WPF library is made accessible via COM interop).

So, the thing is: I can create, open and show WPF windows (this works fine), but I don’t have an Application instance. Application.Current is null. I use the WPF classes, but I operate them outside the WPF application framework.

Currently, the only drawback of this solution is that exceptions in WPF window event handler code are silently swallowed:

void Button_click(sender as object, e as RoutedEventArgs) {
    ...
    // some exception occurs here, but nobody hears her scream
    ...
}

I don’t like that. I’d like to log them and show error messages.

My question: Is there a way to globally catch unhandled exceptions in this scenario or do I have to add a gerneric try-catch-log block to every WPF window event handler code I write?

What I have tried:

  • Attaching to AppDomain.CurrentDomain.UnhandledException. Doesn’t work. Exceptions don’t get there.
  • Reading the relevant parts of MSDN regarding WPF and Win32 interop (Ref 1, Ref 2, Ref 3). Exceptions are not mentioned there.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:12:42+00:00Added an answer on June 4, 2026 at 7:12 pm

    Attach to the Dispatcher instead:

    Dispatcher.CurrentDispatcher.DispatcherUnhandledException += (sender, e) => { 
        // Show message, log exception, etc. 
    }; 
    

    If no dispatcher exists yet, accessing CurrentDispatcher automatically creates a singleton Dispatcher which will also be used by the WPF windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am struggling with the best way to handle a WPF application that has
I'm implementing a wpf application which display a list of items, and provides the
I have a View Model class in a WPF application that has some very
Many WPF examples use CollectionViewSource as DataSource for DataBinding. It provides sorting and other
Many types in WPF derive from Freezable . It provides immutability to mutable POCO
WPF allows to specify linear affine transform on graphical objects. With this you can
WPF controls have certain properties (UserControl.Resources, UserControl.CommandBindings) that can have items added to them
I am trying to test a WPF application using the UI-Automation framework that MSFT
I'm just starting to work with Silverlight (no WPF experience either) and am having
I'm trying to embed Windows-Sidebar-Widgets into my own .Net Application (WPF and C#), but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.