Re: To wrap or not to wrap?
"Chronic Philharmonic" <karl.uppiano@verizon.net> 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 ))report( "Copy failed." );
close( g ); }
else report( "Can't open beta for writing." );
close( f ); }
else report( "Can't open beta for writing." );
try
{ f = fopen( "alpha", "r" );
try
{ g = fopen( "beta", "w" );
try
{ copy( g, f ); }
catch( final Exception exception )
{ report( "Copy failed." ); }
finally
{ close( g ); }}
catch( final Exception exception )
{ report( "Can't open beta for writing." ); }
finally
{ close( f ); }}
catch( final Exception exception )
{ report( "Can't open alpha for reading." ); }