Kotlin try-catch block as an expression
As we know that an expression returns a value. In Kotlin, it's easy to use the try-catch block as an expression. And, the expression value will be either the last expression of the try block or the last expression of the catch block.
Consider the below example demonstrating the use of the try-catch block as an expression.
Example:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer