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
-
SQL Server (and SQL Server Express) supports two authentication modes: 1. Windows Authentication mode 2. Mixed Mode (Windows Authentication ...
-
Methods A Method is a procedure built into the class. They are a series of statements that are executed when called. Methods allow us to han...
-
Conditional Statements If....Else statement If conditional expression is one of the most useful control structures which allows us to execut...
-
Getting Started (Continue) Look at the form with the title bar Form1. This is how your program will look like. Everything you will place on ...
-
Adding Controls to the Form There are many controls you can use with your program: Buttons, Text Boxes, Pictures, Scroll Bars and more. You ...
-
4 Reusable Components and the FCL Up to this point I have spoken quite a bit about the goals of the .NET Framework, as well as what it ...
-
Differences Between Java and C/C++ It is no secret that the Java language is highly derived from the C and C++ languages. Because C++ is cur...
-
Data Access with Server Explorer Visual Basic allows us to work with databases in two ways, visually and code. In Visual Basic, Server Explo...
-
Learning about Events Visual Basic is "Event Driven" language. What does it mean? Everything that happening, launch an event. You...
-
5.1 The .NET Framework: Big Picture Figure 5‑1 The .NET Framework in Context Looking at Figure 5‑1 we see the lifespan of managed c...
No comments:
Post a Comment