aspose file tools*
The moose likes Java in General and the fly likes exception doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "exception doubt" Watch "exception doubt" New topic
Author

exception doubt

priya pratheepp
Ranch Hand

Joined: Apr 02, 2008
Posts: 59
Hi friends,

below is one of the module of java program.Can anybody explain exception declared is correct.If yes please explain.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38788
    
  23
if (file.exists()) file.isFile();

looks incorrect.

No, your exception handling looks incorrect.

Declare your reader objects and set them to null.

Declare a try, followed by catches for FileNotFoundException and IOException. Put appropriate handling in the catches, preferably NOT System.exit().

Inside the try, put another try, but no catches. Make it a try-finally.
The bit about if(reader != null) reader.close(); goes in the finally.
Everything else goes inside the inner try.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
This is decompiled code, isn't it? I do hope you're doing that for legitimate reasons...

The method declares that it throws IOException. But then it catches most/all IOExceptions internally and calls System.exit() silently. This could be poor code: why catch those IOExceptions if you're declaring that you throw IOException.

Calling System.exit() anywhere is usually wrong - especially with a zero exit code (typically meaning "success") and no log or error message.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
priya pratheepp
Ranch Hand

Joined: Apr 02, 2008
Posts: 59
thank you for your quick reply...

This is one decompiled code..what is this
MISSING_BLOCK_LABEL_143 means...

My work is i have to do some modification in this program.First of all i did not get the lines...

once again thanks
priya pratheepp
Ranch Hand

Joined: Apr 02, 2008
Posts: 59
Hi Peter

this is not legitimate code..This is my company file.I decompile using jad and have to do some modification.First i can't understant the exception that is why i posted...
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
It looks like the decompiler has done a rather bad job of reconstructing the original source code. But then, one can't expect a decompiler to produce nice code like a good developer would.

As already mentioned, there are also signs that even the original code was not very good.

If you know what the contract of this method is, you might be better completely rewriting it, rather than trying to modify the cryptic code from the decompiler.

Silly question, but if the code belongs to your company, why don't you have the original source?
priya pratheepp
Ranch Hand

Joined: Apr 02, 2008
Posts: 59
Hi
This is the original code..but soem lines are modified..due to documentation problem i decomplied class file

my original code
public static void copy(String dest_name, String Content)
throws IOException
{
File destination_file = new File(dest_name);
FileOutputStream destination = null;
try
{
File file;
if(destination_file.exists())
destination_file.isFile();
else
file = parent(destination_file);
destination = new FileOutputStream(destination_file);
destination.write(Content.getBytes());
}
catch(Exception e)
{
sb.append("<BR>" + e.toString());
}
finally
{
if(destination != null)
try
{
destination.close();
}
catch(IOException e)
{
System.exit(0);
}
}
return;
}
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception doubt