The Java exceptions framework
As described in Chapter 1, Getting Started with Java 17, an unexpected condition can cause the Java Virtual Machine (JVM) or the application code to create and throw an exception object. As soon as that happens, the control flow is transferred to the catch
clause, that is, if the exception was thrown inside a try
block. Let’s look at 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
, you 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 to by the s
variable...