java - Can I miss the catch clause to throw exception to its caller? -


what kind of problem may occur code? think exception occurs, code can throw exception caller. not generate trouble.

how can improve it?

public static void cat(file named) {   randomaccessfile input = null;   string line = null;   try {     input = new randomaccessfile(named, “r”);     while ((line = input.readline()) != null {       system.out.println(line);     }     return;   } {     if (input != null) {       input.close();     }   } } 

what kind of problem may occur code?

since public class filenotfoundexception extends ioexception

you can change method to:

public static void cat(file named) throws ioexception 

and don't need try-catch blocks.

and caller should catch exception thrown method.

but why don't want catch exceptions?


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -