Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "leftmost" mean in that definition?

Tags:

java

exception

JLS at the 14.20.1 says:

If the run-time type of V is assignment compatible with (§5.2) a catchable exception class of any catch clause of the try statement, then the first (leftmost) such catch clause is selected.

What is leftmost? We put catch clauses from top-to bottom as, for instance:

try{ }
catch(IndexOutOfBoundException e){ }
catch(SQLException e){ }
catch(NullPointerException e){ }
//etc
like image 325
St.Antario Avatar asked Dec 20 '22 10:12

St.Antario


1 Answers

This has nothing to do with any new language features of Java.

The term "leftmost" pertains simply to the earliest-occurring catch clause. Picture the code as a one-dimensional sequence of tokens, extending from left to right. That is how the language parser sees it.

Therefore all that stipulation states is that the first matching catch-clause is entered.

like image 52
Marko Topolnik Avatar answered Dec 22 '22 01:12

Marko Topolnik