When your method potentially "leaks" any checked exception, that exception or an ancestor type must be explicitly announced in the THROWS clause. Checked exception = Exception or descendant.
So compiler will "check" that exposure of "checked" exceptions are announced via THROWS.
Unchecked exceptions have no requirement for THROWS. Unchecked exception = RuntimError or descendant.
Sample from few years back. Separate checked exception class for each external system and one for SQL errors.
API NVO handles each exception - or - converts it to system-specific checked exception.
API NVO handles each returned error code - or - converts it to system specific checked exception.
- Each public function in n_api_efs declares THROWS ex_efs.
Runtime errors are transformed to ex_efs exceptions.
- Each public function in n_api_dkjord declares THROWS ex_dkjord.
Runtime errors and error codes are transformed to ex_dkjord exceptions.
- Each public function in n_api_excel declares THROWS ex_office.
- Each public function in n_api_word declares THROWS ex_office.
Runtime errors incl. OLE exceptions are transformed to ex_office exceptions.
int function of_processData(...)
THROWS ex_SQL // ex_SQL + RuntimeError exposed to caller
TRY
// Call bunch of external systems
...
return 1
CATCH (ex_SQL lex_database)
... Database error
THROW lex_database // Expose to caller
CATCH (ex_Office lex_office)
... Word, Excel, etc.
CATCH (Exception lex_other)
... Electronic-Filing, DKJord, etc.
CATCH (RuntimeError lex_runtime)
// Need to catch and rethrow explicitly
// Otherwise, "Finally" will silence runtime errors
THROW lex_runtime // Expose to caller
FINALLY
... cleanup
END TRY
return -1