0% found this document useful (0 votes)
67 views3 pages

05 Handout 1

Uploaded by

edwrdjms16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views3 pages

05 Handout 1

Uploaded by

edwrdjms16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

IT1712

Exception Handling
Basic Exception Handling
• An exception is an event that occurs during the execution of a program that disrupts the normal flow
of instructions.
• Exception handling is the process used to change the normal flow of code execution if a specified
exception occurs.
• Exceptions that occur during compilation are called checked exceptions.
Exception Description
ClassNotFoundException The class is not found.
IllegalAccessException Access to a class is denied.
InstantiationException Attempt to create an object of an abstract class or an interface.
NoSuchMethodException A requested method does not exist.
• Unchecked exceptions are exceptions that occur during execution. These are also known as runtime
exceptions.
Exception Description
ArithmeticException Arithmetic error, such as an integer divided by 0
ArrayIndexOutOfBoundsException Accessing an invalid index of the array
ArrayStoreException Assigning a value to an array index that does not match
the expected data type
InputMismatchException Entering a value that does not match the expected data
type
NullPointerException Invalid use of a null reference
NumberFormatException Invalid conversion of a string to a numeric format
StringIndexOutOfBoundsException Accessing an invalid index (character) of a string

try, catch, and finally


• A try block is a block of code that might throw an exception that can be handled by a matching catch
block.
• A catch block is a segment of code that can handle an exception that might be thrown by the try block
that precedes it.

05 Handout 1 *Property of STI


Page 1 of 3
IT1712

• The getMessage() method can be used to determine Java’s message about the exception.
Syntax: System.out.println(exceptionName.getMessage());
• Only one (1) try block is accepted in a program but there can be multiple catch blocks.

• A user-defined exception is created by extending the Exception class.


• The finally block contains statements which are executed whether or not an exception is thrown.
There can only be one (1) finally block after a try-catch structure but it is not required.

User-Defined Exceptions
• A user-defined exception is created by extending the Exception class.

05 Handout 1 *Property of STI


Page 2 of 3
IT1712

• A throw statement sends an exception out of a block or a method so it can be handled elsewhere.

Output:

References:
Baesens, B., Backiel, A. & Broucke, S. (2015). Beginning java programming: The object-oriented approach.
Indiana: John Wiley & Sons, Inc.
Farrell, J. (2014). Java programming, 7th edition. Boston: Course Technology, Cengage Learning
Savitch, W. (2014). Java: An introduction to problem solving and programming, 7th edition. California: Pearson
Education, Inc.

05 Handout 1 *Property of STI


Page 3 of 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy