For Programmers: Free Programming Magazines  


Home > Archive > VC Language > May 2006 > const throw()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author const throw()
Jack

2006-05-30, 4:14 am

Hi,
If I have a const throw() trailer on the end of a function, how can it help
me improve my code?
like this
int add() const throw();
I saw some programmers did this...
Thanks
Jack


Arman Sahakyan

2006-05-30, 4:14 am

Hi,

Actually, you have no 'const throw' but 'throw'; const is a part of method
prototype.



--
======
Arman


"Jack" wrote:

> Hi,
> If I have a const throw() trailer on the end of a function, how can it help
> me improve my code?
> like this
> int add() const throw();
> I saw some programmers did this...
> Thanks
> Jack
>
>
>

Ulrich Eckhardt

2006-05-30, 8:08 am

Jack wrote:
> If I have a const throw() trailer on the end of a function, how can it
> help me improve my code?
> like this
> int add() const throw();
> I saw some programmers did this...


The 'throw()' is the promise that the function will never throw an
exception. This is checked at runtime and std::unexpected is invoked when
it did throw one nonetheless.

You might be interested to look at the Boost guidelines:
http://boost.org/more/lib_guide.htm

Uli


Alex Blekhman

2006-05-30, 8:08 am

Jack wrote:
> If I have a const throw() trailer on the end of a
> function, how can it help me improve my code?
> like this
> int add() const throw();
> I saw some programmers did this...


Short answer: don't do this. Using throw specification most
likely won't gain anything you don't have already while can
deteriorate optimizations significantly. I suggest you to
read "Exception-specification rationale" section in the
document that Ulrich posted.

For comprehensive discussion read this:

"A Pragmatic Look at Exception Specifications"
http://www.ddj.com/dept/cpp/184401544

"Exception Safety and Exception Specifications: Are They
Worth It?"
http://www.gotw.ca/gotw/082.htm


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com