try, like if and when, can be used as an expression. Whatever is returned by the try block or the executed catch block becomes the value returned by the expression.

So, in this case, since we are trying to get the length of a null String, we fall into the catch block and our expression evaluates to -1.

You can learn more about this in:
Run Edit