Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception doubt

 
priya pratheepp
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50268
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
priya pratheepp
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic