| Mobile | RSS

Implementing User Defined Exceptions

In addition to the built-in exceptions, you can create customized exception as per the application requirements. Each application that you create might have specific constraints. For example, in case of a train reservation application, a passenger must specify the destination. Also, a ticket has to be bought for a passenger who is above three years [...]

[ More ] 3rd Dec, 2009 | No Comment | Posted in Java

Java Tutorial : Exception-Handling – Summary

Errors can be broadly categorized into two groups on the basis of whether the compiler is able to handle the error or not, such as compile time errors and runtime errors. An exception is a run-time error that can be defined as an abnormal event that occurs during the execution of a program and disrupts [...]

[ More ] 29th Nov, 2009 | No Comment | Posted in Java
Rethrowing an Exception

Java Tutorial : Throwing An Exception – Part 2

Java Tutorial : Throwing An Exception – Part 1 Printing a Stack Trace When an exception is caught, you can find out the method or the line of the code where the exception is raised by using the printStackTrace() method. You can call the printStackTrace() method for printing the stack trace. The objects of the [...]

[ More ] 30th Oct, 2009 | 1 Comment | Posted in Java
Displaying the Description of an Exception

Java Tutorial : Throwing An Exception – Part 1

You can throw an exception explicitly using the throw statement. For example, you need to throw an exception when a user enters a wrong loginID or password. The throws clause is used to list the types of exceptions that can be thrown during the execution of a method in a program. Using the throw Statement [...]

[ More ] 20th Oct, 2009 | 1 Comment | Posted in Java
Unreachable Code Problem

Java Tutorial : Implementing Exception Handling – Part 2

Handling the Unreachable Code Problem The multiple catch blocks generate unreachable code error. If the first catch block contains the Exception class object then the subsequent catch blocks are never executed. The Exception class being the superclass of all the exception classes catches various types of exceptions. The Java compiler gives an error stating that [...]

[ More ] 18th Oct, 2009 | No Comment | Posted in Java

Java Tutorial : Implementing Exception Handling

When an unexpected error occurs in a method, Java creates an object of the type Exception. After creating the Exception object, Java sends it to the program by throwing the exception. The Exception object contains information about the type of error and the state of the program when the exception occurred. You need to handle [...]

[ More ] 14th Oct, 2009 | 1 Comment | Posted in Java

Java Tutorial : Built-in Exceptions

The built-in exceptions in Java are categorized on the basis of whether the exception is handled by the Java compiler or not. Java consists of the following categories of built-in exceptions: Checked Exceptions Unchecked Exceptions Checked Exceptions Checked exceptions are the objects of the Exception class or any of its subclasses excluding the Runtime Exception [...]

[ More ] 12th Oct, 2009 | No Comment | Posted in Java
Exception Hierarchy

Java Tutorial : Exception Classes

Exception Handling To handle exceptions, the Java run-time system searches for an exception-handler. In Java, a catch statement is an exception-handler that is used to handle an exception. The search for an exception-handler begins with the method in which the exception is raised. If no appropriate exception-handler is found, the Java run-time system searches the [...]

[ More ] 11th Oct, 2009 | No Comment | Posted in Java

Java Tutorial : Exception Handling

The term exception in Java indicates an exceptional event. It can be defined as an abnormal event that occurs during program execution and disrupts the normal flow of instructions. The abnormal event can also be an error in the program. Errors in a Java program are categorized into two groups: compile-time errors and run-time errors. [...]

[ More ] 28th Sep, 2009 | 3 Comments | Posted in Java