lecture15 - Administrative Issues Exceptions Lecture 15...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Exceptions Lecture 15 Administrative Issues • Ongoing – Homework 3 due now – Program 3 due June 13 th From Last Time… • JBuilder Demo – Arrays of object references – Static methods and variables – Sorting objects Exceptions • Discovered many runtime errors – Divide by zero – Array index out-of-bounds • Some errors generate exceptions Exceptions are objects that represent an unusual or erroneous situation – An exception is thrown when an error occurs Exception Example • When covering arrays, we mentioned the ArrayIndexOutOfBoundsException int sum; int [] myArray = new int [10]; sum = myArray[0] + myArray[23]; Generates an exception because index 23 is out-of-bounds Dealing with Exceptions • When an exception is generated, three options – Don’t handle it at all – Handle it where it occurs – Handle it at some other point in the program
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Option 1: Ignoring the Exception Ignoring Exceptions • What happens to ignored exceptions? – They halt your program •Ex am p l e – As we saw in previous lectures, the ArrayIndexOutOfBoundsException will halt your program – Dividing by zero will halt your program – A message is produced describing the exception Ignoring Exceptions In JBuilder Exception Messages • When program halts, the exception message is displayed • Message describes error – Exception Object’s Class – An optional text message – Code location where exception was thrown • Also known as the “stack trace” java.lang.ArithmeticException: / by zero at playpen.playpenProgram.main(playpenProgram.java:13)
Background image of page 2
Handling Exceptions • Usually we want to prevent a program from halting • Exceptions should be
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/15/2009 for the course ASTRONOMY 1000 taught by Professor Kim during the Spring '01 term at Yonsei University.

Page1 / 6

lecture15 - Administrative Issues Exceptions Lecture 15...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online