Java Exception Hierarchy in Automation
-
Throwable: Root class.
-
Error: Fatal JVM issues (OutOfMemoryError).
-
Exception: Application issues we can catch.
-
RuntimeException (Unchecked): NullPointerException, IllegalArgumentException, TimeoutException.
-
Checked Exceptions: IOException, InterruptedException (must be declared or handled).
public class AutomationErrorHandler {
public static void executeWithRetry(Runnable action) {
try {
action.run();
} catch (RuntimeException e) {
System.err.println("Action failed: " + e.getMessage());
throw new AutomationException("Automation step failed: " + e.getMessage(), e);
} finally {
System.out.println("Step execution completed cleanup.");
}
}
}