1 parent b225fd8 commit fcb3884Copy full SHA for fcb3884
1 file changed
OOP/Exception Handling/Multi_catch_Pipe_Operator.java
@@ -0,0 +1,20 @@
1
+// -- Multi-Catch (Pipe Operator) -- //
2
+
3
+import java.io.IOException;
4
+import java.sql.SQLException;
5
6
+public class Multi_catch_Pipe_Operator {
7
+ public static void main(String[] args) {
8
+ try {
9
+ simulateError();
10
+ }
11
+ // Using the pipe '|' to catch multiple types in one block
12
+ catch (IOException | SQLException ex) {
13
+ System.out.println("Handled: " + ex.getClass().getSimpleName());
14
15
16
17
+ static void simulateError() throws SQLException {
18
+ throw new SQLException("Database connection failed");
19
20
+}
0 commit comments