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
-
ADO .NET Most applications need data access at one point of time making it a crucial component when working with applications. Data access i...
-
The SQL AVG aggregate function selects the average value for certain table column. Have a look at the SQL AVG syntax: SELECT AVG(Column1) FR...
-
Please do this exercise at the command line instead of using NetBeans. This is to learn the concept of packaging without the help of NetBean...
-
Structures Structures can be defined as a tool for handling a group of logically related data items. They are user-defined and provide a met...
-
package interfaceexercise; // Define an interface with three abstract methods. // Any class that implements this interface has to // impleme...
-
The SQL IN clause allows you to specify discrete values in your SQL WHERE search criteria. THE SQL IN syntax looks like this: SELECT Column1...
-
4.3 Using the FCL “Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.” The IO strea...
-
To whom is this tutorial directed? This tutorial is for those people who want to learn programming in C++ and do not necessarily have any pr...
-
SQL Server (and SQL Server Express) supports two authentication modes: 1. Windows Authentication mode 2. Mixed Mode (Windows Authentication ...
-
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...
No comments:
Post a Comment