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 Programmer > Re: To wrap or ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 9 of 16 Topic 52595 of 55513
Post > Topic >>

Re: To wrap or not to wrap?

by "Chronic Philharmonic" <karl.uppiano@[EMAIL PROTECTED] > May 10, 2008 at 06:33 PM

"Stefan Ram" <ram@[EMAIL PROTECTED]
> wrote in message 
news:exceptions-20080509145219@[EMAIL PROTECTED]
> "Chronic Philharmonic" <karl.uppiano@[EMAIL PROTECTED]
> writes:
>>Returning null instead of the exception that was originally thrown 
>>requires
>>the caller to check for null every time, or blindly use the null value
>
>  I assume that one wants to copy a file and thus needs to open
>  a file for reading and a file for writing and then invoke a
>  copy operation.
>
>  I now will write this once in the C style with zero checking
>  and once in the Java style with a try statement.
>
>  Does the try-style look more readable? Can it be simplified?
>  (Possibly I was not using the simplest way to write it.)
>
> if( f = fopen( "alpha", "r" ))
> { if( g = fopen( "beta", "w" ))
>  { if( copy( g, f ))re****t( "Copy failed." );
>    close( g ); }
>  else re****t( "Can't open beta for writing." );
>  close( f ); }
> else re****t( "Can't open beta for writing." );
>
> try
> { f = fopen( "alpha", "r" );
>  try
>  { g = fopen( "beta", "w" );
>    try
>    { copy( g, f ); }
>    catch( final Exception exception )
>    { re****t( "Copy failed." ); }
>    finally
>    { close( g ); }}
>  catch( final Exception exception )
>  { re****t( "Can't open beta for writing." ); }
>  finally
>  { close( f ); }}
> catch( final Exception exception )
> { re****t( "Can't open alpha for reading." ); }

Without specifically rewriting your logic, I can only say that this isn't 
how my exception handlers typically look. I tend to use one big try block,

with several catch blocks at the end, to deal with things that I can deal 
with, or let the exception fly if I can't deal with it, or if I want the 
exception itself to re****t the failure. I don't usually concern myself
with 
re****ting things like "copy failed" at the granular level.

It is difficult for me to provide examples of what I mean that fit in a 
single method or code snippet, because structured exception handling is
more 
of an architectural endeavor, requiring a more holistic approach to error 
handling. I could send you the source code to my WxService project 
(http://mysite.verizon.net/Karl_Uppiano/wxservice.html)
if you're 
interested.
 




 16 Posts in Topic:
To wrap or not to wrap?
Aaron Fude <aaronfude@  2008-05-08 15:19:42 
Re: To wrap or not to wrap?
ram@[EMAIL PROTECTED] (S  2008-05-08 22:54:08 
Re: To wrap or not to wrap?
=?ISO-8859-1?Q?Arne_Vajh=  2008-05-08 19:13:32 
Re: To wrap or not to wrap?
Aaron Fude <aaronfude@  2008-05-08 16:33:14 
Re: To wrap or not to wrap?
=?ISO-8859-1?Q?Arne_Vajh=  2008-05-08 19:36:50 
Re: To wrap or not to wrap?
ram@[EMAIL PROTECTED] (S  2008-05-08 23:44:34 
Re: To wrap or not to wrap?
"Chronic Philharmoni  2008-05-09 05:57:53 
Re: To wrap or not to wrap?
ram@[EMAIL PROTECTED] (S  2008-05-09 12:54:18 
Re: To wrap or not to wrap?
"Chronic Philharmoni  2008-05-10 18:33:24 
Re: To wrap or not to wrap?
"Daniel Dyer" &  2008-05-09 00:37:00 
Re: To wrap or not to wrap?
"Daniel Dyer" &  2008-05-09 00:42:54 
Re: To wrap or not to wrap?
Tom Anderson <twic@[EM  2008-05-09 00:37:43 
Re: To wrap or not to wrap?
Patricia Shanahan <pat  2008-05-08 20:46:58 
Re: To wrap or not to wrap?
Roedy Green <see_websi  2008-05-09 03:48:55 
Re: To wrap or not to wrap?
java_killer <ggl.book.  2008-05-09 00:48:08 
Re: To wrap or not to wrap?
Lew <lew@[EMAIL PROTEC  2008-05-09 09:17:21 

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 Dec 3 20:13:38 CST 2008.