K
kvnsmnsn
I've written a little program that takes two strings as input. It
converts the first string to an integer index and then applies that
index to the second string, using the <charAt> method of class
<String>. I wanted to check for the possibility that the index might
be too long for the second string, so in such a case my code tries to
"throw" exception <ArrayIndexTooLargeException>, which I declare ear-
lier in my program. However, when I try to compile this program I get
the error message:
[kvnsmnsn@phuture Lab3]$ javac Aioob.java
Aioob.java:15: cannot find symbol
symbol : variable ArrayIndexTooLargeException
location: class Aioob
{ throw ArrayIndexTooLargeException;
^
1 error
[kvnsmnsn@phuture Lab3]$
Anybody have any idea what I'm doing wrong, and what I'd need to do to
accomplish what I'm trying to accomplish? My code follows.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
####################################################################
public class Aioob
{
private class ArrayIndexTooLargeException
extends ArrayIndexOutOfBoundsException
{}
public static void main ( String[] arguments)
{
int index;
if (arguments.length == 2)
{ try
{ index = Integer.parseInt( arguments[ 0]);
if (index >= arguments[ 1].length())
{ throw ArrayIndexTooLargeException;
}
System.out.println
( "\"" + arguments[ 1] + "\".charAt( " + index + ") == '"
+ arguments[ 1].charAt( index) + "'.");
}
catch (NumberFormatException excptn)
{ System.out.println
( "Couldn't convert \"" + arguments[ 0] + "\" to an
integer.");
}
catch (ArrayIndexTooLargeException excptn)
{ System.out.println
( "Index " + arguments[ 0] + " out of bounds for string \""
+ arguments[ 1] + "\".");
}
}
else
{ System.out.println( "Usage is\n Aioob <index> <string>");
}
}
}
converts the first string to an integer index and then applies that
index to the second string, using the <charAt> method of class
<String>. I wanted to check for the possibility that the index might
be too long for the second string, so in such a case my code tries to
"throw" exception <ArrayIndexTooLargeException>, which I declare ear-
lier in my program. However, when I try to compile this program I get
the error message:
[kvnsmnsn@phuture Lab3]$ javac Aioob.java
Aioob.java:15: cannot find symbol
symbol : variable ArrayIndexTooLargeException
location: class Aioob
{ throw ArrayIndexTooLargeException;
^
1 error
[kvnsmnsn@phuture Lab3]$
Anybody have any idea what I'm doing wrong, and what I'd need to do to
accomplish what I'm trying to accomplish? My code follows.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
####################################################################
public class Aioob
{
private class ArrayIndexTooLargeException
extends ArrayIndexOutOfBoundsException
{}
public static void main ( String[] arguments)
{
int index;
if (arguments.length == 2)
{ try
{ index = Integer.parseInt( arguments[ 0]);
if (index >= arguments[ 1].length())
{ throw ArrayIndexTooLargeException;
}
System.out.println
( "\"" + arguments[ 1] + "\".charAt( " + index + ") == '"
+ arguments[ 1].charAt( index) + "'.");
}
catch (NumberFormatException excptn)
{ System.out.println
( "Couldn't convert \"" + arguments[ 0] + "\" to an
integer.");
}
catch (ArrayIndexTooLargeException excptn)
{ System.out.println
( "Index " + arguments[ 0] + " out of bounds for string \""
+ arguments[ 1] + "\".");
}
}
else
{ System.out.println( "Usage is\n Aioob <index> <string>");
}
}
}