Skip to main content

Posts

Showing posts with the label exception

“Try-Catch-Finally” vs Throws

Its really confusing sometimes when different people ask me to use “try-catch” or throws in my code while they religiously do the code reviews… Some ask me to stick to try-catch and others suggest just throwing all exceptions         After getting frustrated for a couple of times, I finally decided to read through various resources and find out for myself what’s best! Below is the gist of my findings:   What’s a Try-Catch Block? Oh yes the answer lies in its definition. A try-catch block helps us handle an exception. So basically its our own Exception Handling Construct…So use it when you would want your program to handle its exceptions by itself.   Thus we should fall back to using Throws when your program/function isn’t handling the exceptions it raises. You simply pass on the exceptions to its higher layer Pass the ball!!!   Hope this helps!

Java Exception: The type java.lang.Object cannot be resolved

Exeption Text: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files There can be two solutions to this problem when it occurs in Eclipse Eclipse doesn’t know where the J2EE jar file is present. To give the path: - Right Click Project you are working on from Package Explorer- Go to Properties- Go to Java Build Path from the right tree structure- Go to Libraries Tab- Choose Add External Jars Button- Select J2EE.jar file normally in C:\Sun\AppServer\lib folder.- Hit Finish In Eclipse, the cause of this problem is that you somehow deleted the SYSTEM JRE LIBRARY associated with your project. Simple fix in Eclipse:-Right Click Project you are working on from Package Explorer-Go to Properties-Go to Java Build Path from the right tree structure-Go to Libraries Tab-Choose Add Library Button-Select JRE System Library-Hit Next, the Radio button will prompt the Workspace default JRE, and let it be that way-Hit Finish