[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Exams] [Examples] [Book] [Tutorial] [API]
Back to When Things Go Wrong. On to Project Discussion.
Held Thursday, September 16, 1999
Overview
Today, we will conclude our discussion of exceptions and complete a short lab on exceptions. We will then delve into the wonders of Java's arrays which bear some resemblance to Scheme's misnamed vectors.
Notes
Contents
Handouts
Summary
throw new MyException(message);
public MailMessage(String sender, String recipient, String body)
throws Exception
{
if ((sender == null) || (sender.equals(""))) {
throw new Exception("Invalid Sender");
}
// ...
} // MailMessage(String, String, String)
public class MyException
extends Exception
{
} // class MyException
MyException.
public class MyException
extends Exception
{
public MyException(String msg) {
super(msg);
} // MyException(String)
} // class MyException
MyException with
a String as a parameter, use that string as the parameter to the
constructor of Exception (my superclass).''
java.lang.Integer,
java.lang.Double, and many many more.
Integer.MIN_VALUE and
Integer.MAX_VALUE. (The same is true for other types.)
intValue
(and related things).
String[] args. The first argument
is args[0] and is a string.
Integer.parseInt() permits you to to convert
integers to strings.
String whatever;
// ...
int i = Integer.parseInt(whatever);
// ...
Integer class can build an
Integer object from a string.
The intValue method extracts the integer value.
String whatever;
// ...
int i = new Integer(whatever).intValue();
// ...
Spend about fifteen minutes on this lab.
Count.java.
import SimpleOutput;
/**
* A simple program to illustrate command-line input.
*
* @author Samuel A. Rebelsky
* @version 1.0 of September 1999
*/
public class Count {
public static void main(String[] args) {
// Prepare for output.
SimpleOutput out = new SimpleOutput();
// Get the maximum number to print.
int n = Integer.parseInt(args[0]);
for (int i = 0; i <= n; ++i) {
out.print(i + " ");
}
out.println();
} // main(String[])
} // class Count
Count.java.
% /home/rebelsky/bin/ji Count 4 % /home/rebelsky/bin/ji Count 4 5 % /home/rebelsky/bin/ji Count four % /home/rebelsky/bin/ji Count
Count.java so that it prints clearer error messages
in each case.
Tuesday, 10 August 1999
Wednesday, 15 September 1999
Thursday, 16 September 1999
PrintParams
Back to When Things Go Wrong. On to Project Discussion.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Exams] [Examples] [Book] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/99F/Outlines/outline.13.html
Source text last modified Thu Sep 16 12:44:31 1999.
This page generated on Tue Sep 21 11:10:05 1999 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu