🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5774

Re: try & catch

#5774
From: Robert G. Hoover
Date: Fri, 15 Jul 2005 14:16
72 lines
3837 bytes
Thanks for the tip. I'm using BCB6. I added a "catch (Exception 
&exception)" block to my code and it is catching the exception now with 
multiple lines in the "try" block.

As for finding the cause, my bet is in multiple threads trying to access 
the same canvas? I have the main application thread running and an 
independent thread running in the background. Only the background thread 
is altering my GUI, whether it's a TForm->Canvas or a TPanel->Caption 
that I'm using as a status bar. It's possible that the main app thread 
is trying to process a WM_PAINT message at the same time a background 
thread UpdateStatus is trying to change the GUI??? I guess that could 
account for it. You know, come to think of it, I've seen this "Canvas 
does not allow drawing" error from time to time in other apps where no 
background thread is running. <shrug> At least the exception is being 
caught now and not crashing the program. My customers will be happy the 
program doesn't bomb out in the middle of a long acquisition run. ;)

Thanks for the help!

Rob




Remy Lebeau (TeamB) wrote:
> "Robert G. Hoover" <not.a.real.address@anywhere.sorry> wrote in message
> news:42d3fe5e@newsgroups.borland.com...
> 
> 
>>catch (...)
> 
> 
> Which version of BCB are you actually using?  If BCB6, then '...' does not
> havdle VCL exceptions as well as it did in previous versions.  You should
> always catch VCL exceptions by type explicitally:
> 
>     catch (const Exception &)
> 
> 
>>The catch is never being executed. The debugger lands on the
>>"Repaint" line after the exception is thrown "Canvas does not
>>support drawing!".
> 
> 
> The exception is liely being handled by the VCL internally so that your own
> code never sees it.  Of course, the debugger sees all exceptions regardless
> of where they are thrown or how they are handled.  Pressing F9 passes the
> exception back to the application for normal handling.
> 
> 
>>But if I break up the statements into individual try/catch
>>statements, the catch executes and writes the entry to my log file.
> 
> 
> There is no difference between having 1 try/catch block or multiple.  An
> exception is an exception, and if it actually reaches your code, having a
> single try/catch block will handle it just as well as multiple blocks.
> 
> 
>>My program does very sophisticated image acquisition, processing,
>>and analysis and keeps crashing out because of this "Canvas does not
>>support drawing!", resulting in incomplete acquisition runs.
> 
> 
> The best way to handle an exception is to not cause an exception to be
> thrown in the first place.  Are you locking the Canvas every time you draw
> on it?  Are you drawing on it from multiple threads at the same time?
> 
> 
> Gambit
> 
> 
Technical Details
Message-ID: <42d7c561@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!news-hog.berkeley.edu!ucberkeley!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <42d3fe5e@newsgroups.borland.com> <42d41033$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,40a42ffcaae937ff
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Fri, 15 Jul 2005 10:16:58 -0400
From: "Robert G. Hoover" <not.a.real.address@anywhere.sorry>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: try & catch
References: <42d3fe5e@newsgroups.borland.com> <42d41033$1@newsgroups.borland.com>
In-Reply-To: <42d41033$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.142.36.34
Message-ID: <42d7c561@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1121437025 67.142.36.34 (15 Jul 2005 07:17:05 -0700)
Lines: 72
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!news-hog.berkeley.edu!ucberkeley!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail