Can a constructor throw an exception?

E

exquisitus

What's the best way to notify callee that something went awry during
object creation (i.e. in constructor invocation) ?

Thanks
 
C

Chris Uppal

exquisitus said:
What's the best way to notify callee that something went awry during
object creation (i.e. in constructor invocation) ?

Just about the only thing you /can/ do is throw an exception.

I should add, though, that if there's enough logic in the constuctor for it to
be reasonable for it to go awry, then that /may/ be a hint that you've got too
much logic there.

-- chris
 
E

exquisitus

Thanks for the info Chris - much appreciated

Chris said:
exquisitus wrote:




Just about the only thing you /can/ do is throw an exception.

I should add, though, that if there's enough logic in the constuctor for it to
be reasonable for it to go awry, then that /may/ be a hint that you've got too
much logic there.

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top