Java Exception handling using try...catch

http‮s‬://www.lautturi.com
Java Exception handling using try...catch

use try catch to handle exception in java

/**
 * @author lautturi.com
 * Java example: Java Exception Example
 */

import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		try {
			int divideByZero = 5 / 0;
		} catch (Exception e) {
			System.out.println("exception occurs");
			System.out.println(e);
			System.out.println("exception message " + e.getMessage());
		}
	}
}

output:

exception occurs
java.lang.ArithmeticException: / by zero
exception message / by zero
Created Time:2017-09-05 11:42:01  Author:lautturi