View RSS Feed

Java Exception

Java exceptions and errors.

  1. User defined exception

    by , 01-08-2012 at 01:01 PM
    You can customize and write your own user defined exceptions. Following class extends the Exception class and writes a new “MyException” which is thrown at some point in your code.

    Java Code: This is an example of user defined exception
    public class MyException extends Exception {
    /* class definition of constructors goes here */
    public MyException() {
    public MyException (String errorMessage) {
    super (errorMessage);

    Updated 01-14-2012 at 07:48 PM by Java Exception

    Tags: exception Add / Edit Tags
  2. Exception handling best practices

    by , 01-08-2012 at 12:58 PM
    Following are the best practices when catching and handling exceptions in your java code.

    • Do not catch “Exception” directly in your code. Java exception handling is not polymorphic. If you catch Exception, it can catch IOException or any other descendent type.

    Name:  62.JPG
Views: 1081
Size:  35.3 KB

    Catching Exceptions

    • Exception handling supports the stack trace of any error in your code. Always throw an exception early in your code to make this ...
  3. Java error handling

    by , 01-08-2012 at 12:56 PM
    When a hard failure or link failure occurs in virtual machine, JVM throws an Error. These Errors are not caught by the typical java programs.

    When a problem occurs in the code, an Exception is thrown and is caught by the program explicitly. Base class of all Exception classes is Exception class. All other are derived classes. Below image shows a complete hierarchy of the exceptions in java.

    Name:  62.JPG
Views: 1222
Size:  16.3 KB

    Throwable and subclasses

  4. Basics of Exceptions

    by , 11-29-2011 at 04:09 AM
    One of the key aspects of programming is understanding how to handle exceptions. An exception is a problem that prevents the continuation of the current method or scope. It’s important to distinguish an exceptional condition from a normal problem, in which you have enough information in the current context to somehow cope with the difficulty. With an exception, you cannot continue processing because you lack the information necessary to address the problem in its current context. The only recourse ...

    Updated 11-30-2011 at 04:19 AM by Java Exception

    Error Handling , Tutorial
  5. Catching an Exception

    by , 11-29-2011 at 04:07 AM
    Following on from our previous tip on exceptions, in this tip we will look at catching an exception. One of the key concepts to understand is the concept of a guarded region. It is a section of code that might produce exceptions and is followed by the code to handle a particular exception. They are often grouped into all the possible exceptions for a particular method or piece of code.

    The try block
    The first part of the region is the try block. This is when you’re inside a ...