ioexception

Ioexception - Exceptions An Exception is an object that describes an unusual or erroneous situation-If an exception is ignored by the program the

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: Exceptions An Exception is an object that describes an unusual or erroneous situation.-If an exception is ignored by the program, the program will terminate and produce an appropriate message. Example:-------------------------------------------------------------------------------------- public class DividingByZero { //----------------------------------------------------------------- // Deliberately divides by zero to produce an exception. //----------------------------------------------------------------- public static void main (String args) { int numerator = 10; int denominator = 0; System.out.println (numerator / denominator); System.out.println ("This text will not be printed."); } }------------------------------------------------------------------------------------ Output Exception in thread “main” java.lang.ArithmeticException: / by zero at DividingByZero.main(DividingByZero.java:11)-------------------------------------------------------------------------------------- The call stack trace : indicating where the exception occurred. This exception was produced by the line “System.out.println (numerator / denominator);” because it divides by zero. At this point, the program is terminated and the next line is never executed. We can avoid the termination of a program caused by an exception by using: try statements....
View Full Document

This note was uploaded on 06/11/2009 for the course CS 205214 taught by Professor Balasooriya/kouvetakis during the Spring '09 term at ASU.

Page1 / 6

Ioexception - Exceptions An Exception is an object that describes an unusual or erroneous situation-If an exception is ignored by the program the

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

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