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 830983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:07:53+00:00 2026-05-15T04:07:53+00:00

How to catch exception in the main thread if the exception occurs in the

  • 0

How to catch exception in the main thread if the exception occurs in the secondary thread?

The code snippet for the scenario is given below:

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        Thread th1 = new Thread(new ThreadStart(Test));
        th1.Start();               
    }
    catch (Exception)
    { 

    }
}

void Test()
{
    for (int i = 0; i < 100; i++)
    {
        Thread.Sleep(100);

        if (i == 2)
            throw new MyException();
    }
}
  • 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-15T04:07:54+00:00Added an answer on May 15, 2026 at 4:07 am

    You can add a Application.ThreadException Event handler:

    Joe is correct. Given the above windows forms code I was assuming Windows forms:

    This event allows your Windows Forms
    application to handle otherwise
    unhandled exceptions that occur in
    Windows Forms threads. Attach your
    event handlers to the ThreadException
    event to deal with these exceptions,
    which will leave your application in
    an unknown state. Where possible,
    exceptions should be handled by a
    structured exception handling block.

    See Unexpected Errors in Managed Applications

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

Sidebar

Related Questions

I keep hearing that catch (Exception ex) Is bad practise, however, I often use
Is it better to do this: try { ... } catch (Exception ex) {
Does the using catch the exception or throw it? i.e. using (StreamReader rdr =
When we can catch an exception like: Violation of UNIQUE KEY constraint 'IX_Product'. Cannot
It is discouraged to simply catch System.Exception . Instead, only the "known" exceptions should
My technical lead insists on this exception mechanism: try { DoSth(); } catch (OurException)
Example int *ptr; *ptr = 1000; can I catch memory access violation exception using
Should I catch exceptions for logging purposes? public foo(..) { try { ... }
How to catch exceptions in Haskell?
Is there some way to catch exceptions which are otherwise unhandled (including those thrown

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.