Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > catching exceptions

Reply
Thread Tools

catching exceptions

 
 
Samuele Armondi
Guest
Posts: n/a
 
      07-06-2003
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.


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-07-2003
"Samuele Armondi" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
Samuele Armondi
Guest
Posts: n/a
 
      07-07-2003
"Victor Bazarov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Samuele Armondi" <(E-Mail Removed)> 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!


 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      07-08-2003

"Samuele Armondi" <(E-Mail Removed)> wrote in message news:3f09ecfa$(E-Mail Removed)...
> 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) { ...


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Catching unhandled exceptions using HttpModules Amil Hanish ASP .Net 0 04-12-2006 11:51 PM
Catching exceptions in JSP when they occur in Servlets Mick Java 0 08-06-2003 01:12 PM
Re: Catching exceptions that are never thrown Adam Maass Java 5 07-22-2003 10:58 PM
Re: Catching exceptions that are never thrown Mike Schilling Java 2 07-16-2003 08:36 PM
Re: catching exceptions from web user controls Marina ASP .Net 2 07-08-2003 04:48 PM



Advertisments