Termination of Program Due To Unhandled Exception Java Example Program

Termination of Program Due To Unhandled Exception Example Program

public class ProgramTerminationDueToUnhandledException {
    public static void main(String[] args) {
        String value = null;
        
        //Trying to print length of null string
        //Program is stopped abruptly
        System.out.println("Length of string is : "+value.length());
    }
}

Sample Output

Exception in thread "main" java.lang.NullPointerException
	at learnjavaprograms.ProgramTerminationDueToUnhandledException.main(ProgramTerminationDueToUnhandledException.java:13)
Java Result: 1