Skip to main content

Posts

Exception handling program2

PROGRAM- class ExceptionDem2 {             public static void main(String args[ ])             {                System.out.println("In the Main block");                try                {                   System.out.println("In the try block");                   int a=10,b=0,c;                   c=a/b;                   System.out.println("Result="...

PROGRAM of exception

PROGRAM- class ExceptionDem1 {             public static void main(String args[ ])             {                System.out.println("In the Main block");                try                {                   System.out.println("In the try block");                   int a=10,b=0,c;                   c=a/b;                   System.out.println("Result="...

Advantage of Exception/Error Handling with When Exception/Error can occur?

Advantage of Exception/Error Handling: ·          Error-handling codes are separated from the normal program flow to increase the readability and maintainability. ·          This location of the exception/error is known exactly as entire stack trace is available to the user. This is very helpful in debugging. ·          Programmer gets a chance to recover from the error/abnormal condition. ·          With java, it is not must to test if an exception/error condition happens. Adding more error/exception simply requires adding more catch clauses, but the original program flow need not be touched. W hen Exception/Error can occur? There are many cases where abnormal condition occurs during program execution, such as: ·          The class file you want to load may be missing or in...

PROGRAM OF EXCEPTION Handling:

PROGRAM- class ExceptionDemo1   {             public static void main(String args[ ])             {                         int a=Integer.parseInt(args[0]);                         int b=Integer.parseInt(args[1]);                         int c;                         c=a/b;                      ...

Exception Handling:

Exception Handling: An exception/error is an abnormal condition that breaks/disrupts the normal program flow. The abnormal condition occurs at run-time i.e. during code execution. For example, a C program gets terminated when division by zero is encountered at the run-time as this is not a defined operation and result in run-time error. The other familiar example in case of C-language is that of null pointer exception, which occurs when we try to access a memory location through an un-initialized pointer. The program gets terminated in this case also. Java has a separate construct for exception/error handling like C++. It is possible to recover from an exception/error at run-time and continue the program exception using the exception-handling construct. A java exception/error is an object of class Exception/Error or one of its sub-class. JVM creates an object of class Exception/Error or one o          f their sub-class whenever e...