Skip to content

Commit fcb3884

Browse files
authored
Create Multi_catch_Pipe_Operator.java
1 parent b225fd8 commit fcb3884

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)