Thursday, October 15, 2015

How To Use Exception Handling (Try Catch) in Java Programming Language + video tutorial

How To Use Exception Handling (Try Catch) in Java Programming Language

The Following script is the simplest way to declaring and using Exception Handling (Try Catch) Java programming language:

Java Program:

public class UseExceptionHandling {
    public static void main(String[] args) {
        float x, y, result;
        
        x = 100;
        y = 0; //change y = 0 to raise an exception
        
        try
            result = x / y;
            System.out.println("result = "+ result);
        } catch(Exception e){
            System.out.println("Error : "+ e);
        }
    }
    
}

output x=100, y=10 :

output x=100, y=0 :


ShadowOfBdg© - All rights reserved. 


No comments:

Post a Comment