~/ learn/ comp-308/ cards/ Chaining, rethrow, custom hierarchies & logging
1 of 7

Wrap a low-level cause when re-throwing

Wrap a low-level cause when re-throwing

Answer

try { loadEvents(file); } catch (IOException e) { throw new ControllerException("could not start", e); }

Passing `e` as the cause preserves the original stack trace; `getCause()` retrieves it and the trace shows it under `Caused by:`.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/c5443c0e-86a0-4770-be59-9b4094ca2d42/flashcard utf-8 LF