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
-
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...
-
CONSTANTS,VARIABLES AND KEYWORDS: CONSTANTS: Two types of constants those are: a)primary constants b)secondary constants a)In primary consta...
-
Introduction: In this exercise, you will exercise the concept scope variable. Steps to follow: 1. Write ScopeOfVariable.java as shown in Cod...
-
# When the user submits form, his information is sent to the corresponding servlet file because we've set the ACTION attribute to point ...
-
MouseMove, MouseDown and MouseUp Events Lets check out the Command Button's MouseMove, MouseDown and MouseUp events. We will do that lik...
-
Data Adapter Configuration Wizard Generating DataSet To create a DataSet, select Data->Generate DataSet from the main menu. From the dial...
-
JSP scripting elements let you insert Java code into the servlet that will be generated from the current JSP page. There are three forms: ...
-
Introduction: In this exercise, you are going to build and run a sample Java program called CommandLineusing NetBeans. The sample program c...
-
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 ...
-
Introduction: In this exercise, you will exercise the concept object creation using new keyword. We will learn how you are going to create ...
No comments:
Post a Comment