0
# Error Handling
1
2
Comprehensive exception hierarchy and error reporting system for handling migration failures, validation errors, and operational issues.
3
4
## Capabilities
5
6
### Exception Hierarchy
7
8
```java { .api }
9
/**
10
* Main Flyway exception - base for all Flyway-specific exceptions
11
*/
12
public class FlywayException extends RuntimeException {
13
public FlywayException(String message);
14
public FlywayException(String message, Throwable cause);
15
public FlywayException(Throwable cause);
16
}
17
18
/**
19
* Exception thrown when Flyway validation fails
20
*/
21
public class FlywayValidateException extends FlywayException {
22
public FlywayValidateException(ErrorDetails errorDetails, String... validationErrors);
23
public ErrorDetails getErrorDetails();
24
}
25
26
/**
27
* Exception thrown when statement execution is blocked
28
*/
29
public class FlywayBlockStatementExecutionException extends FlywayException {
30
public FlywayBlockStatementExecutionException(String message);
31
}
32
```
33
34
### Error Information
35
36
```java { .api }
37
/**
38
* Interface for error codes
39
*/
40
public interface ErrorCode {
41
String getCode();
42
String getMessage();
43
}
44
45
/**
46
* Core error codes enumeration
47
*/
48
public enum CoreErrorCode implements ErrorCode {
49
NON_EMPTY_SCHEMA_WITHOUT_SCHEMA_HISTORY_TABLE,
50
FAILED_RESOLVING_MIGRATIONS,
51
FAILED_VALIDATING_MIGRATIONS,
52
VALIDATION_FAILED,
53
CHECKSUM_MISMATCH,
54
TYPE_MISMATCH,
55
DESCRIPTION_MISMATCH;
56
57
public String getCode();
58
public String getMessage();
59
}
60
61
/**
62
* Detailed error information
63
*/
64
public interface ErrorDetails {
65
ErrorCode getErrorCode();
66
String getMessage();
67
String getFilename();
68
Integer getLineNumber();
69
}
70
```
71
72
## Usage Examples
73
74
```java
75
// Basic error handling
76
try {
77
flyway.migrate();
78
} catch (FlywayException e) {
79
System.err.println("Migration failed: " + e.getMessage());
80
e.printStackTrace();
81
}
82
83
// Validation error handling
84
try {
85
flyway.validate();
86
} catch (FlywayValidateException e) {
87
ErrorDetails details = e.getErrorDetails();
88
System.err.println("Validation failed:");
89
System.err.println("Error code: " + details.getErrorCode().getCode());
90
System.err.println("Message: " + details.getMessage());
91
if (details.getFilename() != null) {
92
System.err.println("File: " + details.getFilename());
93
}
94
}
95
96
// Comprehensive error handling
97
try {
98
MigrateResult result = flyway.migrate();
99
System.out.println("Migration successful");
100
} catch (FlywayValidateException e) {
101
// Handle validation errors
102
System.err.println("Validation failed: " + e.getMessage());
103
} catch (FlywayException e) {
104
// Handle general Flyway errors
105
System.err.println("Flyway operation failed: " + e.getMessage());
106
} catch (Exception e) {
107
// Handle unexpected errors
108
System.err.println("Unexpected error: " + e.getMessage());
109
}
110
```