MIT SP 772 - Exceptions (23 pages)

Previewing pages 1, 2, 22, 23 of 23 page document View the full content.
View Full Document

Exceptions



Previewing pages 1, 2, 22, 23 of actual document.

View the full content.
View Full Document
View Full Document

Exceptions

35 views

Problems/Exams


Pages:
23
School:
Massachusetts Institute of Technology
Course:
Sp 772 - Internet Technology in Local and Global Communities
Internet Technology in Local and Global Communities Documents

Unformatted text preview:

MIT AITI Lecture 14 Exceptions Handling Errors with Exceptions Kenya 2005 In this lecture you will learn What an exception is Some exception terminology Why we use exceptions How to cause an exception How to deal with an exception About checked and unchecked exceptions Some example Java exceptions How to write your own exception MIT Africa Internet Technology Initiative 2005 What is an exception An exception or exceptional event is an event that occurs during the execution of a program that disrupts the normal flow of instructions The following will cause exceptions Accessing an out of bounds array element Writing into a read only file Trying to read beyond the end of a file Sending illegal arguments to a method Performing illegal arithmetic e g divide by 0 Hardware failures MIT Africa Internet Technology Initiative 2005 Exception Terminology When an exception occurs we say it was thrown or raised When an exception is dealt with we say it is handled or caught The block of code that deals with exceptions is known as an exception handler MIT Africa Internet Technology Initiative 2005 Why use exceptions Compilation cannot find all errors To separate error handling code from regular code Code clarity debugging teamwork etc Worry about handling error elsewhere To separate error detection reporting and handling To group and differentiate error types Write error handlers that handle very specific exceptions MIT Africa Internet Technology Initiative 2005 Decoding Exception Messages public class ArrayExceptionExample public static void main String args String names Bilha Robert System out println names 2 The println in the above code causes an exception to be thrown with the following exception message Exception in thread main java lang ArrayIndexOutOfBoundsException 2 at ArrayExceptionExample main ArrayExceptionExampl e java 4 MIT Africa Internet Technology Initiative 2005 Exception Message Format Exception messages have the following format exception class additional



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

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 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?