As we have described in Chapter 1, Getting Started with Java 12, an unexpected condition can cause the Java Virtual Machine (JVM) to create and throw an exception object, or the application code can do it. As soon as it happens, the control flow is transferred to the catch clause, if the exception was thrown inside a try block. Let's see an example. Consider the following method:
void method(String s){
if(s.equals("abc")){
System.out.println("Equals abc");
} else {
System.out.println("Not equal");
}
}
If the input parameter value is null, one could expect to see the output as Not equal. Unfortunately, that is not the case. The s.equals("abc") expression calls the equals() method on an object referred by the s variable, but, in case the s variable is null, it does not refer to any object...