lecture15 - Administrative Issues Exceptions Lecture 15...

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
Option 1: Ignoring the Exception Ignoring Exceptions What happens to ignored exceptions? – They halt your program • Example – 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) JBuilder Demo Option 2: Handling An Exception Where It Occurs
Image of page 2
Handling Exceptions
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern