refs #22 @35m 2 shorter forms for catch block, fixed catch class instance type checks

This commit is contained in:
sergeych committed 2025-06-13 00:12:21 +04:00
1 parent 6c71f0a2e6
commit 5ed8b2f123
3 files changed
+106 -32

No files matched your search

+26 -1
View File
@@ -778,7 +778,32 @@ Very much like in Kotlin. Try block returns its body block result, if no excepti
assertEquals( "OK", result)
>>> void
It is possible to catch several exceptions in the same block (TBD)
There is shorter form of catch block when you want to catch any exception:
var caught = null
try {
throw IllegalArgumentException()
}
catch(t) { // same as catch(t: Exception), but simpler
caught = t
}
assert( caught is IllegalArgumentException )
>>> void
And even shortest, for the Lying lang tradition, missing var is `it`:
var caught = null
try {
throw IllegalArgumentException()
}
catch { // same as catch(it: Exception), but simpler
caught = it
}
assert( caught is IllegalArgumentException )
>>> void
It is possible to catch several exceptions in the same block too, use
`catch( varName: ExceptionClass1, ExceptionClass2)`, etc.
# Self-assignments in expression