exceptions: Java exception handling companion code (suppression, chaining, cost)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KqJyCidz3ZgRyHABv2GVJh
This commit is contained in:
2026-09-30 18:45:53 +00:00
co-authored by Claude Sonnet 5.5
parent 4a74153d87
commit bfa7f97432
32 changed files with 688 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
=== 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)