forked from aws/aws-secretsmanager-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLExceptionUtils.java
More file actions
38 lines (33 loc) · 1.1 KB
/
Copy pathSQLExceptionUtils.java
File metadata and controls
38 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.amazonaws.secretsmanager.util;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* SQL Exception Utilities
*/
public class SQLExceptionUtils {
/**
* Checks the thrown exception and all parent exceptions and returns true if
* a SQLException with a matching error code is found.
*
* @param t The SQLException to check
* @param errorCode The error code to check for.
* @return True if the exception or any parent exception is a SQL Exception
* and getErrorCode matches the error code. Otherwise, false.
*/
public static boolean unwrapAndCheckForCode(Throwable t, int errorCode) {
final List<Throwable> list = new ArrayList<>();
while (t != null && list.contains(t) == false) {
list.add(t);
if ( t instanceof SQLException && ((SQLException)t).getErrorCode() == errorCode ) {
return true;
}
t = t.getCause();
}
return false;
}
/**
* Hide constructor for static class
*/
private SQLExceptionUtils() { }
}