java - How should I handle the IOException thrown by the function BufferReader.readline()? -


everytime encounter java exception ,i fell dilemma whether should throw exception directly or catch exception .if catch exception ,should print stack trace or more work in catch block?for example , reading file line line,the function bufferedreader.readline() throws ioexception ,it seems checked(compared unchecked exception) exception because user told deal exception explicitly,right?although have deal , seems can nothing else print stack trace, ,it strange.should catch or throw exception? if catch it,what should in catch block?

this which part responsible exception.

if, example, you're developing tool package jar, maybe should throw ioexception in method prasadioutils.readfile(string path), should provide function read file, not handle exception.

in contrast, should catch exception when invoking method prasadioutils.readfile(string path) in code. because logic part, , 1 responsible handling exception make own project more robust , fault-tolerant.

this how understand, hope helps. :)

p.s. if you're still confused there's nothing printing expection's stack trace, can google exception chaining further information. java design pattern, maybe it'll make understand more on exception.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -