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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:27:45+00:00 2026-06-08T00:27:45+00:00

If I have the following situation: Execute() creates a new thread and executes function

  • 0

If I have the following situation:

  1. Execute() creates a new thread and executes function GetSession() in it.
  2. Execute() executes GetSession() again in it’s own thread.
  3. Execute() joins the thread from (1).

My question is:

What happens if GetSession() throws an exception from the thread spawned in (1) while the thread Execute() is running in is currently running GetSession() itself?

Does the exception re-thrown from the extra thread propagate up to Execute() and cause it to go to its handler even though it’s from a different thread?


Here’s some sample code to demonstrate the issue:

I just made this up in the window here (it’s a mock-up), so appologies for syntax errors.

public void Execute()
{
    //Some logon data for two servers.
    string server1 = "x", server2 = "y", logon = "logon", password = "password";

    //Varialbes to store sessions in.
    MySession session1, session2;

    try
    {
        //Start first session request in new thread.
        Thread thread = new Thread(() =>
            session1 = GetSession(server1, logon, password));
        thread.Start();

        //Start second request in current thread, wait for first to complete.
        session2 = GetSession(server2, logon, password));
        thread.Join();
    }
    catch(Exception ex)
    {
        //Will this get hit if thread1 throws an exception?
        MessageBox.Show(ex.ToString());
        return;
    }
}

private MySession GetSession(string server, string logon, string password)
{
    try
    {
        return new MySession(server, logon, password);
    }
    catch(Exception Ex)
    {
        throw(Ex);
    }
}
  • 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-08T00:27:48+00:00Added an answer on June 8, 2026 at 12:27 am

    What happens if GetSession() throws an exception from the thread spawned in (1) while the thread Execute() is running in is currently running GetSession() itself?

    The threaded version will raise an unhandled exception, which will trigger AppDomain.UnhandledException. Unless this is explicitly handled there, it will tear down the application.

    Does the exception re-thrown from the extra thread propagate up to Execute() and cause it to go to its handler even though it’s from a different thread?

    No. It will be unhandled.


    Note that this is one of the advantages of the TPL. If you use Task instead of a Thread, you can make this propogate the exception back to the main thread:

    try
    {
        //Start first session request in new thread.
        Task<Session> task = Task.Factory.StartNew(() => GetSession(server1, logon, password));
    
        //Start second request in current thread, wait for first to complete.
        session2 = GetSession(server2, logon, password));
        session1 = task.Result; // This blocks, and will raise an exception here, on this thread
    }
    catch(Exception ex)
    {
        // Now this will get hit
        MessageBox.Show(ex.ToString());
        return;
    }
    

    Note, however, that this will be an AggregateException, and requires special handling.

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

Sidebar

Related Questions

I have the following situation: function Mach3Code(Str: String): String; var StrOut: String; begin StrOut
As in my own answer to my own question , I have the situation
I have the following situation which generates a OID error when retriving data from
I have the following situation. From an application located in https://subdomain.mydomain.com I am trying
my situation is as follows: I have the following function var showHideMemberContent = function(){
I have following situation - Have a MongoService class, which reads host, port, database
I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have following situation, String a=<em>crawler</em> <em> Yeahhhhh </em></a></h3><table; System.out.println(a.indexOf(</em>)); It returns the 11
I have following situation: String a = A Web crawler is a computer program

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.