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

  • SEARCH
  • Home
  • 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 726167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:25:16+00:00 2026-05-14T06:25:16+00:00

I have a fun issue where during application shutdown, try / catch blocks are

  • 0

I have a fun issue where during application shutdown, try / catch blocks are being seemingly ignored in the stack.

I don’t have a working test project (yet due to deadline, otherwise I’d totally try to repro this), but consider the following code snippet.

class IndexNotFoundException : Exception { }

public static string RunAndPossiblyThrow(int index, bool doThrow)
{
    try
    {
        return Run(index);
    }
    catch(IndexNotFoundException e)
    {
         if(doThrow)
             throw;
    }
    return "";
}

public static string Run(int index)
{
    if(_store.Contains(index))
        return _store[index];
    throw new IndexNotFoundException ();
}

public static string RunAndIgnoreThrow(int index)
{
    try
    {
        return Run(index);
    }
    catch(IndexNotFoundException e)
    {
    }
    return "";
}

During runtime this pattern works famously. We get legacy support for code that relies on exceptions for program control (bad) and we get to move forward and slowly remove exceptions used for program control.

However, when shutting down our UI, we see an exception thrown from “Run” even though “doThrow” is false for ALL current uses of “RunAndPossiblyThrow”. I’ve even gone so far as to verify this by modifying code to look like “RunAndIgnoreThrow” and I’ll still get a crash post UI shutdown.

Mr. Eric Lippert, I read your blog daily, I’d sure love to hear it’s some known bug and I’m not going crazy.

EDIT
This is multi-threaded, and I’ve verified all objects are not modified while being accessed

EDIT
Explicitly show exception is ours

EDIT
forgot to mention, this is on closing, and unfortunately visual studio cannot catch the crash directly. It’s likely crashing on a thread other than the UI thread, and once the main closes, this closes. I’ve only been able to debug this by repeatedly running & closing the application, with task manager open, “Create Dump File” and looking at the resulting 400+mb mess in Windbg. Win7 64 for reference. Make sure this makes sense to you.

EDIT

The following code on shutdown still shows the same exception.

class IndexNotFoundException : Exception { }

public static string RunAndPossiblyThrow(int index, bool doThrow)
{
    try
    {
        return Run(index);
    }
    catch
    {
    }
    return "";
}

public static string Run(int index)
{
    if(_store.Contains(index))
        return _store[index];
    throw new IndexNotFoundException ();
}

The only thing that seems to get rid of the exception is to go straight to

class IndexNotFoundException : Exception { }

public static string RunAndPossiblyThrow(int index, bool doThrow)
{
    try
    {
        return Run(index);
    }
    catch
    {
    }
    return "";
}

public static string Run(int index)
{
    if(_store.Contains(index))
        return _store[index];
    return "";
}

Naturally the exception’s gone, but my fears of going crazy are still present.

EDIT

it just got worse… this still crashes…

class IndexNotFoundException : Exception { }

public static string RunAndPossiblyThrow(int index, bool doThrow)
{
    try
    {
        throw new IndexNotFoundException();
    }
    catch
    {
    }
    return "";
}

EDIT
I have a distinct feeling this is going to get me nowhere. On top of the wierd behavior, I can also note that during execution of the UI in the above case, the try catch is being executed faithfully. My UI doesn’t crash & it’s full of empty strings. However once I start closing the UI, the crash shows itself and the try catch no longer holds back the exception.

EDIT & final
Apparently the dump file was listing in it the most recent first-chance exception. I verified this by creating a new project that threw inside a try catch & slept for 10 seconds. During the wait I got the .dmp file & sure enough, my completely caught exception was showing up.

I’ll mark some points for the useful answers, however unfortunately there’s still no rhyme or reason why my code is crashing…

  • 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-05-14T06:25:17+00:00Added an answer on May 14, 2026 at 6:25 am

    There are various exceptions that cannot be caught. Stack Overflow in particular! Could one of these be occurring somewhere in your code?

    See http://www.bluebytesoftware.com/blog/PermaLink,guid,223970c3-e1cc-4b09-9d61-99e8c5fae470.aspx

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

Sidebar

Related Questions

I'm having a fun issue, I have LiveReload working in Chrome, so I know
I have a fun application written in Visual Studio (C#), and I'm wondering -
I have recently been working on a Pastebin script (for fun) and I've come
Here is a fun issue I am wrestling with. I have a Multi Dimensional
I've been working on a simple tile-based terrain generator for fun, and have run
Variants are always fun, eh? I am working on a legacy application that was
Have a fun issue with sharepoint calendar view filtering. That code works fine: SPSecurity.RunWithElevatedPrivileges(delegate()
Alright this is my first day with JQuery so have fun with these functions
I have a fun script: DECLARE @StartDT DATE DECLARE @MinDOS DATE DECLARE @TableName VARCHAR(50)
I have a function fun that returns a double. I want to call the

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.