import java.io.*;
import java.sql.*;
class Demo {
void multiCatch() {
try {
// ... code that might throw IOException or SQLException ...
} catch (IOException | SQLException e) {
System.err.println("transient error: " + e.getMessage());
}
}
// Wrap & re-throw with the original as cause
void wrap() throws AppException {
try {
Files.newBufferedReader(Path.of("config.toml"));
} catch (IOException e) {
throw new AppException("config load failed", e); // preserves stack
}
}
// getCause() walks the chain
void inspect(Throwable t) {
for (var cur = t; cur != null; cur = cur.getCause()) {
System.out.println("→ " + cur);
}
}
}
Create a free account and build your private vault. Share publicly whenever you want.