Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: throwing ex...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 9 of 9 Topic 16067 of 16204
Post > Topic >>

Re: throwing exceptions on instantiation

by Lew <lew@[EMAIL PROTECTED] > May 10, 2008 at 09:52 AM

Roedy Green wrote:
> On Fri, 09 May 2008 04:06:49 GMT, thufir <hawat.thufir@[EMAIL PROTECTED]
>
> wrote, quoted or indirectly quoted someone who said :
> 
>> The makeGuest is working fine, probably because the data is fine.  If
the 
>> constructor of Guest throws a DataException, though, I wouldn't want 
>> makeGuest to return a new Guest!  I'm not quite sure what it should do,

>> if not that, though...
> 
> If you do something like 
> 
> Thing thing = new Thing();
> 
> And the constructor throws an exception, thing will be unmodified
> since the assigment is the last step.

In this particular case, 'thing' will fall out of scope; there won't be a 
'thing' to be unmodified.

This scope vs. exception tension occurs often in making connections or 
grabbing other resources, for example.

im****t some.version.of.Resource;

Resource res = null;
try
{
   res = getResource();
}
catch ( SomeException exc )
{
   handle( exc );
   // for some reason we want to continue
}
....
// time to close
if ( res != null )
{
   res.close();
   res = null;
}

-- 
Lew
 




 9 Posts in Topic:
throwing exceptions on instantiation
thufir <hawat.thufir@[  2008-05-09 04:06:49 
Re: throwing exceptions on instantiation
Knute Johnson <nospam@  2008-05-08 22:04:19 
Re: throwing exceptions on instantiation
thufir <hawat.thufir@[  2008-05-09 09:31:30 
Re: throwing exceptions on instantiation
Knute Johnson <nospam@  2008-05-09 09:15:52 
Re: throwing exceptions on instantiation
Daniel Pitts <newsgrou  2008-05-09 07:55:17 
Re: throwing exceptions on instantiation
thufir <hawat.thufir@[  2008-05-10 07:13:22 
Re: throwing exceptions on instantiation
Lew <lew@[EMAIL PROTEC  2008-05-10 08:24:08 
Re: throwing exceptions on instantiation
Roedy Green <see_websi  2008-05-10 13:03:09 
Re: throwing exceptions on instantiation
Lew <lew@[EMAIL PROTEC  2008-05-10 09:52:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 7:31:03 CDT 2008.