Unformatted text preview:

ExceptionsOverviewUncaught ExceptionsSlide 4try/catchPropagationException Class HierarchyDesigning/Throwing Own ExceptionExceptionsOverview•“An exception is an object that defines an unusual or erroneous situation.”•Examples–Divide by 0–Array index out of bounds–File cannot be found–Follow a null referenceUncaught Exceptionsint a = 5;int b = 0;int c = a/b;Exception in thread "main" java.lang.ArithmeticException: / by zeroat ExceptionsExamples.main(ExceptionsExamples.java:12)Uncaught Exceptions•Call stack trace–info about where the exception occurred–info about all methods that were called to get to the method where the exception occurred Exception in thread "main" java.lang.ArithmeticException: / by zeroat ExceptionsExamples.caller2(ExceptionsExamples.java:20)at ExceptionsExamples.caller1(ExceptionsExamples.java:12)at ExceptionsExamples.main(ExceptionsExamples.java:8)try/catchtry {//statements that may throw an exception} catch(Exception_Type name) {//what to do in case of exception //Exception_Type} catch(Another_Type another_name) {//what to do in case of exception Another_Type}Propagationvoid divider() throws ArithmeticException {int a = 5;int b = 0;int c = a/b;}Exception Class Hierarchy•Throwable–Error–Exception•IOException–EOFException, FileNotFoundException•ClassNotFoundException•RuntimeException–ArithmeticException–ClassCastException–NullPointerExceptionDesigning/Throwing Own Exception•Create a class that extends Exception–OutOfRangeExceptionif out of range {throw new


View Full Document

USF CS 112 - Exceptions

Documents in this Course
Structs

Structs

4 pages

Trees

Trees

25 pages

Strings

Strings

27 pages

Queues

Queues

3 pages

Trees

Trees

24 pages

Arrays

Arrays

5 pages

ArrayList

ArrayList

24 pages

Stacks

Stacks

2 pages

Stacks

Stacks

8 pages

Trees

Trees

24 pages

Stacks

Stacks

8 pages

Queues

Queues

16 pages

Queues

Queues

17 pages

Queues

Queues

17 pages

Load more
Download Exceptions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exceptions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exceptions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?