[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
Back to Conditionals (2). On to Exceptions (2).
Held: Wednesday, 21 September 2005
Summary: Today we consider exceptions, Java's primary technique for reporting and recovering from problems.
Related Pages:
Assignments
Due
Notes:
Overview:
I'll fix it once I get the 'real' stuff working; and
When you try to read an integer you may fail because the user enters a non-number, you might write something like:
/**
* Read an integer.
*
* @exception NumberFormatException
* if the user enters something other than an integer
*/
public int readInt()
throws NumberFormatException
// ...
throws the exception.
public static void main(String[] args)
throws NumberFormatException
{
// ...
int row = in.readInt();
// ...
}
try clause.
catch clause.
try {
// stuff that may have problems
}
catch (ExceptionClass e1) {
// Handle one type of exception
}
catch (AnotherExceptionClass e2) {
// Handle another type of exception
}
finally {
// Clean-up code that is always executed.
}
public static void main(String[] args)
throws Exception
{
// ...
int row = -1;
while (row < 0) {
try {
row = in.readInt();
}
catch (NumerFormatException e) {
out.println("Not a number");
}
} // while
// ...
} // main
java.io.IOException and
java.lang.NumberFormatException.
Back to Conditionals (2). On to Exceptions (2).
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue Dec 6 09:47:23 2005.
The source to the document was last modified on Thu Aug 25 16:15:07 2005.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2005F/Outlines/outline.16.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby