X-Spam-Check-By: sourceware.org
To: cygwin@cygwin.com
From: Eric Lilja <mindcooler@gmail.com>
Subject:  Re: Throwing c++ exception across threads
Date:  Wed, 25 Apr 2007 16:49:05 +0200
Lines: 28
Message-ID: <f0npp0$jr$1@sea.gmane.org>
References:  <f0no2t$pfq$1@sea.gmane.org> <017801c78746$855e2ab0$2e08a8c0@CAM.ARTIMI.COM>
Mime-Version:  1.0
Content-Type:  text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding:  7bit
User-Agent: Thunderbird 2.0.0.0 (Windows/20070326)
In-Reply-To: <017801c78746$855e2ab0$2e08a8c0@CAM.ARTIMI.COM>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

Dave Korn wrote:
> On 25 April 2007 15:20, Eric Lilja wrote:
> 
>> When the user of the program connects to an irc server a thread is
>> spawned that handles communication with the irc server. 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? The things is that the connection code may cause an
>> exception and I want to run that in the connection thread so the UI
>> doesn't freeze while it's waiting for an connection attempt to time-out
>> for instance.
> 
>   How exactly do you propose to "throw an exception across threads" anyway?
> You can't spawn a thread inside a try-catch block and expect that block to
> apply to the new thread....
> 
>     cheers,
>       DaveK

Right, I moved the connection code inside the thread func. There it 
checks for exceptions made during the connection and ends the thread 
(and displaying an error message) if one occurs. If one does not occur, 
it starts handling messages till the connection is closed or an 
exception occurs.

This seems to work without freezing.

- Eric


--
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/

