is it okay to throw exceptions in a `synchronized`...
# getting-started
y
is it okay to throw exceptions in a
synchronized
block?
e
if it makes sense to
y
as in, it's safe: no hidden gotchas to be aware of
e
it's basically
Copy code
try {
    MONITORENTER
    block()
} finally {
    MONITOREXIT
}
(you can't write those bytecode instructions in pure Kotlin but the compiler can)
y
oh. yeah that's as clear as I can hope for, as a person who knows basically nothing about the jvm.
j
In such constructs, the
finally
block always executes, whether the
try
block completed normally or threw an exception. You can read about
try
-
catch
-
finally
constructs in this section of the Java documentation: https://docs.oracle.com/javase/tutorial/essential/exceptions/handling.html And more specifically about `finally`: https://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html