What is an Exception?
Why use exceptions instead of return values?
- Forces error checking
- Cleans up your code by separating the ormal case from the exceptional case.
(The code isn't littered with a lot of
if
-else
blocks checking return values.)
- Low overhead for non-exceptional case
Traditional programming languages set flags or return bad
values like -1 to indicate problems. Programmers often don't
check these values.
Java throws Exception
objects to indicate a problem. These cannot be ignored.
Previous | Next | Top
Last Modified October 21, 1999
Copyright 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu