Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   catching exceptions (http://www.velocityreviews.com/forums/t268115-catching-exceptions.html)

Samuele Armondi 07-06-2003 09:58 PM

catching exceptions
 
Hi everyone,
I vaguely recall someone mentioning that exceptions should be caught as
const in order to avoid unnecessary copying, i.e.
try
{
// blah
}
catch (const exception e)
{
//deal with it
}
Is this the case? If so, why does const stop the object from being copied?
Thanks in advance,
S. Armondi

--
To contact me by email, remove _NOSPAM_ from the address.



Victor Bazarov 07-07-2003 10:02 PM

Re: catching exceptions
 
"Samuele Armondi" <sammyboyuk_NOSPAM_@hotmail.com> wrote...
> I vaguely recall someone mentioning that exceptions should be caught as
> const in order to avoid unnecessary copying, i.e.
> try
> {
> // blah
> }
> catch (const exception e)
> {
> //deal with it
> }
> Is this the case? If so, why does const stop the object from being copied?


It doesn't. You probably want them to be caught by reference:

catch (const exception & e)
{
// deal with it
}

Victor



Samuele Armondi 07-07-2003 10:51 PM

Re: catching exceptions
 
"Victor Bazarov" <v.Abazarov@attAbi.com> wrote in message
news:vgjrh4mtmlhn66@corp.supernews.com...
> "Samuele Armondi" <sammyboyuk_NOSPAM_@hotmail.com> wrote...
> > I vaguely recall someone mentioning that exceptions should be caught as
> > const in order to avoid unnecessary copying, i.e.
> > try
> > {
> > // blah
> > }
> > catch (const exception e)
> > {
> > //deal with it
> > }
> > Is this the case? If so, why does const stop the object from being

copied?
>
> It doesn't. You probably want them to be caught by reference:
>
> catch (const exception & e)
> {
> // deal with it
> }
>
> Victor
>
>

Ok, thanks for the info. I probably just misread it!



Ron Natalie 07-08-2003 02:18 PM

Re: catching exceptions
 

"Samuele Armondi" <sammyboyuk_NOSPAM_@hotmail.com> wrote in message news:3f09ecfa$1_2@mk-nntp-1.news.uk.worldonline.com...
> Hi everyone,
> I vaguely recall someone mentioning that exceptions should be caught as
> const in order to avoid unnecessary copying, i.e.
> try
> {
> // blah
> }
> catch (const exception e)
> {
> //deal with it
> }


Not const, but reference (which may also be const).

catch(exception& e) { ...




All times are GMT. The time now is 10:17 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.