A handler for every throwable, or for fatal errors, lets the program go on after them
What it finds
catch (Throwable t) and catch (Error e) also catch what a program cannot recover from, such as OutOfMemoryError and StackOverflowError, and failed assertions of tests. The program then carries on in a state nobody planned for.
A clause whose block throws, as code that cleans up and rethrows does, is left alone.
From the rule's source, catch_throwable.rs.
class Jobs { void run(Runnable task) { try { task.run(); } catch (Throwable t) {tx0 reports: catching Throwable also catches errors log(t); } try { task.run(); } catch (java.lang.Error e) {tx0 reports: catching java.lang.Error log(e); } try { task.run(); } catch (Throwable t) { cleanup(); throw t; } try { task.run(); } catch (RuntimeException e) { log(e); } } void log(Throwable t) {} void cleanup() {}} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:catch-throwable" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:catch-throwable] reason="..."tx0 explain tx0/java:catch-throwable shows the same in the terminal. Found a false positive? Report it.