Re: exiting a constructor early
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 03/12/04
- Next message: Chris \( Val \): "Re: just for fun"
- Previous message: Chris \( Val \): "Re: What's wrong in this code?"
- In reply to: Francis Glassborow: "Re: exiting a constructor early"
- Next in thread: Francis Glassborow: "Re: exiting a constructor early"
- Reply: Francis Glassborow: "Re: exiting a constructor early"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 13 Mar 2004 00:19:20 +1100
"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
news:1aK0yW0mDbUAFwND@robinton.demon.co.uk...
| In message <c2sacu$21pvvl$1@ID-110726.news.uni-berlin.de>, "Chris ( Val
| )" <chrisval@bigpond.com.au> writes
| >| Function try blocks actually add very little and are rarely if ever
| >| needed in well designed code.
| >
| >Maybe - but, if dealing with exceptions in an constructor,
| >then the function try block is the prefered construct to use :-).
|
| I think not.
Why not ?
Where is a better place to catch exceptions thrown by any
resource allocation in an initialiser list ?
| Once you get into a catch part of a function try block you
| are outside the function and the exception will propagate.
Yes, but the function try block mechanism allows you to 're-throw'
the exception object, and to 're-throw' a different object if you
wish, allowing you to legally break an exception specification.
| If you want to handle an exception in the body of a ctor, do so
| IN THE BODY.
With the function try block syntax though, the 'try' scope *is*
the body of the constructor - the handler is for handling the
exception object - the constructor body need not do it.
| If you do not want to then let it propagate. If you find yourself
| having to do some external handling via a function try block, look
| at your design and ask yourself why that is the case. I think the
| usual answer will be that the class has been poorly designed.
I'm not sure what you're talking about. AFAIU, the function try block
construct is an intimate part of the constructor itself when used, and
it does offer advantages as I've noted.
Cheers.
Chris Val
- Next message: Chris \( Val \): "Re: just for fun"
- Previous message: Chris \( Val \): "Re: What's wrong in this code?"
- In reply to: Francis Glassborow: "Re: exiting a constructor early"
- Next in thread: Francis Glassborow: "Re: exiting a constructor early"
- Reply: Francis Glassborow: "Re: exiting a constructor early"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|