Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it normal for java library code to throw & catch lots of exceptions during "normal" processing?

Tags:

java

More as an experiment, I decided to enable the following breakpoint in the Eclipse debugger: Throwable [Include Subclasses]: caught and uncaught. I then let my code (which is running "fine" as far as I know) run under the debugger, and was surprised to see dozens of exceptions being thrown and caught (previously unknown to me) by standard J2SE library code when my code was running normally for all I know.

For example, here are just some of the Java framework functions I found throwing exceptions: URLClassLoader.findClass, FileDirContext.lookup, and WebappClassLoader.findClassInternal.

Is this considered normal behavior for a Java application? Is this something I should look into? My code seems to be running fine as far as I know.

like image 617
Danger Avatar asked Oct 18 '12 17:10

Danger


1 Answers

Though it is bad to design your code in this way (exceptions are slow, and should be used for exceptional circumstances), Bhesh Gurung's comment is the right way to think about this. Follow the specification of the code you are relying on, and don't worry about the implementation.

like image 193
Cory Kendall Avatar answered Nov 15 '22 00:11

Cory Kendall