Comprog2 Week8 - Session 1-2
Comprog2 Week8 - Session 1-2
COMPUTER
PROGRAMMING 2
Prepared By:
Method Calls
- If a method throws as exception, then calling
that method may result in an exception.
GENERATING EXCEPTIONS
Runtime Exceptions
- Can occur even though the offending piece
of code does not declare that it throws an
exception.
TYPES OF EXCEPTIONS
Checked Exceptions
Unchecked Exceptions
TYPES OF EXCEPTIONS
Checked Exceptions
- The classes which directly inherit
Throwable class except RuntimeException
and Error are known as checked
Exceptions e.g. IOException,
SQLException etc.
- Checked Exceptions are checked at
compile time.
TYPES OF EXCEPTIONS
Unchecked Exceptions
- The classes which inherit
RuntimeException are known as
unchecked Exceptions e.g.
NullPointerExceptions,
ArrayIndexOutOfBoundsException etc.
- Unchecked Exceptions are checked at
runtime.
THE THROWS CLAUSE
General format:
THE THROWS CLAUSE- example
HANDLING EXCEPTIONS
NEXT MEETING--
WEEK 10 SESSION 1:
GUI (Swing Components)
REFERENCES:
https://www.baeldung.com/java-
common-exceptions
https://www.geeksforgeeks.org/types-
of-exception-in-java-with-examples/
https://www.javatpoint.com/exception-
handling-in-java