Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KqJyCidz3ZgRyHABv2GVJh
20 lines
1006 B
Plaintext
20 lines
1006 B
Plaintext
=== try/finally: the close() exception replaces the query() exception ===
|
|
caught: java.lang.IllegalArgumentException: close failed on db-1
|
|
suppressed count: 0
|
|
|
|
=== try-with-resources: query() exception wins, close() exception is attached ===
|
|
caught: java.lang.IllegalStateException: query failed on db-1
|
|
suppressed count: 1
|
|
suppressed: java.lang.IllegalArgumentException: close failed on db-1
|
|
|
|
=== two resources: closed in reverse order, each failure is suppressed ===
|
|
caught: java.lang.IllegalStateException: query failed on B
|
|
suppressed: java.lang.IllegalArgumentException: close failed on B
|
|
suppressed: java.lang.IllegalArgumentException: close failed on A
|
|
|
|
=== what printStackTrace() shows for suppressed exceptions ===
|
|
java.lang.IllegalStateException: query failed on db-1
|
|
at com.ankurm.exceptions.SuppressedDemo$Conn.query(SuppressedDemo.java:9)
|
|
Suppressed: java.lang.IllegalArgumentException: close failed on db-1
|
|
at com.ankurm.exceptions.SuppressedDemo$Conn.close(SuppressedDemo.java:10)
|