~/ learn/ comp-308/ cards/ Exceptions: try, catch, throw
1 of 5

Throw an exception when a guard fails

Throw an exception when a guard fails

Answer

if (level < 0) { throw new IllegalArgumentException("level must be >= 0"); }

`throw` launches the exception object; the method stops immediately and the stack unwinds to the nearest matching handler.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/4921f4ce-0cf6-45be-82ed-9433d4ccdf22/flashcard utf-8 LF