delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/04/26/21:32:01

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Shankar Unni <shankarunni AT netscape DOT net>
Subject: Re: Throwing c++ exception across threads
Date: Thu, 26 Apr 2007 18:31:09 -0700
Lines: 47
Message-ID: <f0rjou$8i4$1@sea.gmane.org>
References: <f0no2t$pfq$1 AT sea DOT gmane DOT org>
Mime-Version: 1.0
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070326 Thunderbird/2.0.0.0 Mnenhy/0.7.5.666
In-Reply-To: <f0no2t$pfq$1@sea.gmane.org>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Eric Lilja wrote:

> [...] Any messages are 
> displayed in an editbox. If a severe error occurs, an exception is 
> thrown. Will there be any problems if I catch these exceptions in the 
> main thread? [...]

Just thinking about that setup makes my head spin. Yes, I suspect 
there'll be lots of problems if you do this. :-)

The very concept of "catching the exception in main" is absurd when 
threads are involved: the whole point of exception catching and throwing 
is that it is totally synchronous, and goes from callee to caller (to 
its caller and so on, until your main()).

All of this only makes sense in the context of one thread. Implicit in 
the catching of an exception is the idea that the exception was thrown 
from _something you called from within that try block_.

Otherwise, you'd have a situation like:

/* parent: */
    func() {
       ...
       // spawn thread
       return;  //!!
    }

    main()
    {
      ...
      func();
      ...
      some_other_random_stuff();
    }

/* child: */
    ...
    throw something;
    ...

Err, but the point from where the thread was created is no longer on the 
stack, because control returned to the parent and then went on somewhere 
else. So even if you attempted to do something bizarre like "hop stacks 
to the parent thread's stack", you'd end up in some random stack frame 
in the parent thread, like "some_other_random_stuff()", which won't be 
expecting that exception and won't know what to do with it...


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019