Introduction:
If you are new to Exception handling, please read "Exception Handling Statements" section of the Java Progamming Tutorial.
Steps to follow:
1. Write ExceptionExample.java as shown in Code-12.1 below. (You are welcome to do this work using either command line tools or NetBeans. The instruction here is given using command line tools. In general, using NetBeans is highly recommended.)
* cd \myjavaprograms
* mkdir exceptionexercise (to match the packaging structure)
* jedit exceptionexercise\ExceptionExample.java
EXAMPLES
package exceptionexercise;
public class ExceptionExample {
public static void main( String[] args ){
try{
System.out.println( args[1] );
} catch( ArrayIndexOutOfBoundsException exp ){
System.out.println("Exception caught! The exception is " + exp);
}
}
}
2. Compile and run the code using a directory structure.
* cd \myjavaprograms (if you are not in this directory already)
* javac exceptionexercise\*.java
* java -classpath . exceptionexercise.ExceptionExample
3. Verify the result
* C:\myjavaprograms>java -classpath . exceptionexercise.ExceptionExample
Exception caught!
Popular Posts
-
This chapter talks about installing SQL Server Express. If you have a licensed version of full SQL Server 2005, you can follow the same step...
-
SYMBOLIC CONSTANTS OR MACRO: In this #define is a macro used for a constant value to be assigned in the program. for example: pi its value i...
-
Simple Binding Generating DataSet To generate a DataSet, select Data->Generate DataSet from the main menu. From the dialog that opens, as...
-
If you expand the node "Databases" on the management studio, you will see the following sub nodes: System Databases Database Snaps...
-
The SQL AND clause is used when you want to specify more than one condition in your SQL WHERE clause, and at the same time you want all con...
-
Lab exercises and homeworks: * Things to check before you start the lab * Chapter 3 (Class #1, Jan. 16th homework) o Exerc...
-
STRINGS: The way a group of integers can be stored in an integer array, similarly a group of characters can be stored in a character array. ...
-
Additional Command Button's Properties Add 1 Command Button to your form, and change the following properties to see what they do. Capti...
-
Using functions we can structure our programs in a more modular way, accessing all the potential that structured programming can offer to us...
No comments:
Post a Comment