Technobuff is celebrating its 1st anniversary . Thanks to our members for making it a success. Us Privacy Policy Disclaimer Java exceptions Back to the index Email this article to a friend Previous Next Exceptions are so common in Java programming that any discussion about Java basics would be incomplete if we didn't talk about exceptions. An exception is a way to indicate an abornmal condition in a program. These conditions come in 2 flavors Errors Exceptions Both of these derive from the java.lang.Throwable class.
Errors indicate fatal conditions, such as out of memory .
These are more on system level and there's nothing much that your program can do to handle an error. You may want to catch errors only in cases where you want to do some simple stuff such as logging the error. Exceptions indicate non-fatal conditions and you should possibly catch these to handle as appropriate. For instance, if your program encounters an exception while trying to initialize data from a file, it can set data to an empty string. In order to handle an exception, you need to catch it.