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
-
A JSP declaration lets you define methods or fields that get inserted into the main body of the servlet class (outside of the service method...
-
JSP pages are high level extension of servlet and it enable the developers to embed java code in html pages. JSP files are finally compiled ...
-
The SQL SELECT INTO statement is used to select data from a SQL database table and to insert it to a different table at the same time. The g...
-
ARRAYS: An array is a group of related data items that share a common name.For instance,we can define an array name salary to represent a se...
-
The SQL JOIN clause is used whenever we have to select data from 2 or more tables. To be able to use SQL JOIN clause to extract data from 2 ...
-
We will use the Customers table to illustrate the SQL LIKE clause usage: FirstName LastName Email DOB Phone John Smith John.Smith@yaho...
-
Learning about Parameters Parameters are variables that being passed to a Sub. Look at the first line of the Command Button's Click even...
-
The SQL WHERE clause is used to select data conditionally, by adding it to already existing SQL SELECT query. We are going to use the Custom...
-
DATATYPES: there are 3 types of datatypes those are: a)primary datatypes b)user-defined datatypes c)derived data types primary datatypes are...
-
This directive lets you include files at the time the JSP page is translated into a servlet. The directive looks like this: The URL s...
No comments:
Post a Comment