Sie sind auf Seite 1von 78

]ara Copyright 2001-2004 1om lunter

]ara Copyright 2001-2004 1om lunter


Chapter 14
cetiov avativg
f av,tbivg cav go rrovg, it ritt.
]ara Copyright 2001-2004 1om lunter
\hat is an Lxception`
14.1 Introduction: deinition o terms
exception exception
An event during program execution that
preents the program rom continuing
normally.
Generally, an error.
]ara Copyright 2001-2004 1om lunter
Other languages react to errors by crashing crashing.
Jaa manages errors in a controlled way.
Jaa permits recoery, i at all possible.
14.1 Introduction
]ara Copyright 2001-2004 1om lunter
\hat users expect when an error happens:
14.1 Introduction: user expectations
-tell tell them an error happened
-sae sae all their work-in-progress, i possible.
-allow allow them to exit the program graceully.
]ara Copyright 2001-2004 1om lunter
In Jaa, when an error happens, we say an
exception has been thrown.
Once an exception has been thrown, the
JVM begins a search begins a search or some logic able to
handle the exception.
14.1 Introduction: Oeriew o Jaa`s Approach
]ara Copyright 2001-2004 1om lunter
1he bit o logic able to handle the exception
is called, naturally, an exception handler exception handler.
\hen the JVM inds the right exception exception
handler, handler, we say the exception has been
caught.
Control is then transerred to the transerred to the
catching block catching block.`
14.1 Introduction: Oeriew o Jaa`s Approach
]ara Copyright 2001-2004 1om lunter
1he exception cav be thrown by the Jaa
Virtual Machine-independent o the
programmer`s control-or .
the programmer ber.etf ber.etf can throw the
error, in response to some problem.
14.1 Introduction: \ho Can 1hrow An Lxception
]ara Copyright 2001-2004 1om lunter
Understand, exception handling is really a kind
o Control llow, akin to the 1` and
8wtch` statements.
1he rationale rationale is this: you want to aoid
cluttering up your program with logic to handle
errors.
So, you moe the error-handling logic o to a
separate place.
14.1 Introduction
]ara Copyright 2001-2004 1om lunter
i., Program is executing.
ii., Something goes wrong-i.e., ero airi.iov.
iii., JVM creates an cepton object.
i., 1he cepton object covtaiv. ivforvatiov
abovt tbe ecetiov that occurred.
., 1he cepton object is sent up the line
until it encounters someone who can catch it.
14.1 Introduction: Lrror landling Sequence
The possible "someones" who can handle the exception are
the methods in the call stack above where the error occurred.
]ara Copyright 2001-2004 1om lunter
Question:
\hat is an cepton object.
Answer:
An instance o the class %hrowable.
\hat makes something an instance o the
class %hrowable?
Answer:
Any class that extends the class
%hrowable, or whose $vercta.. extends that
class.
14.1 Introduction: the Lxception Object
]ara Copyright 2001-2004 1om lunter
Objects that are instances o throwable-
which means they subclass it ,i an interace, or
implement ,i a class,-are etigibte to be tbrorv b,
tbe ]1M in response to an error.
Ater an exception, the JVM works
backwards up the chain |stack| o method
calls, until it encounters a handler` or the
exception-or a Superclass o the
exception-whicheer it encounters irst.
14.1 Introduction: throwable
]ara Copyright 2001-2004 1om lunter
1his process o working back up the chain
looking or a handler is described this way:
Lxceptions propagate error reporting
up the call stack o methods.`
14.1 Introduction: the call stack
]ara Copyright 2001-2004 1om lunter
\hat constitutes a handler` or a particular
exception
ecetiov bavater
A block o code that reacts to a 85ecific ty5e o
ecetiov.
f the program can recoer rom the exception, the
program will resume executing ater the exception handler has
executed.
14.1 Introduction: deinition
]ara Copyright 2001-2004 1om lunter
\hen 1o Use
Lxception landling
]ara Copyright 2001-2004 1om lunter
W Warning! Lxce5tion handling 8hould
only be u8ed for exce5tional 8ituation8
our program must try to preent preent
exceptions exceptions-with normal programming
techniques-such as bounds checking on arrays
or alidation o input data.
Lxception landling is the last line o deense.
14.2 \hen to Use Lxception landling
]ara Copyright 2001-2004 1om lunter
1he Classiication
o
Lxceptions
]ara Copyright 2001-2004 1om lunter
1he Classiication o Lxceptions
As we saw, an Lxception is always an instance
o the interace %hrowable.
ou should try to preent ava catcb all
ceptons, but there is a branch o the
class %hrowable that you should neer neer
attempt to catch attempt to catch: instances o the class
rror.
]ara Copyright 2001-2004 1om lunter
%hrowable
1hese describe program or
user mistakes. 1hese
exceptions should should be
caught.
1hese describe internal
errors and resource
exhaustion inside the JVM.
1hese should NO1 be
caught because they are too
major.
Our starting point,
interace
%hrowable.
rror
cepton
]ara Copyright 2001-2004 1om lunter
%hrowable
rror
cepton
IO IOcepton Runt2e Runt2ecepton
]ara Copyright 2001-2004 1om lunter
%hrowable
rror
cepton
IO IOcepton Runt2e Runt2ecepton
A Runt2ecepton
happens because ,ov ,ov made a
programming error.
Any other exception
occurs because a bad thing
beyond your control beyond your control ,such
as an I,O error, happened
to your otherwise good
program.
]ara Copyright 2001-2004 1om lunter
Lxamples o Runt2ecepton8:
-A bad cast.
-An out-o-bounds array access.
-Attempting to access a null reerence pointer.
Lxamples o Non Non Runt2ecepton8:
-1rying to read past the end o a ile.
-1rying to open a malormed URL.
]ara Copyright 2001-2004 1om lunter
try,
throw and
catch
]ara Copyright 2001-2004 1om lunter
Keywords
Jaa supports exception handling with these keywords:
try,
throw and
catch.
14.4 The Basics oI Java Exception Handling
]ara Copyright 2001-2004 1om lunter
publc cla88 NoceptonHandlng
{
publc 8tatc vod 2an( Strng[] arg8 )
{
nt = 1, y = 0, z = 0;
z = / y;
Sy8te2.out.prntln( /y = + z );
}
}
1his will neer print, nor will it tell you
why it ailed.
1he program just dies.
It has no exce5tion handling.
Diision by zero.
]ara Copyright 2001-2004 1om lunter
publc cla88 Ha8ceptonHandlng
{
publc 8tatc vod 2an( Strng[] arg8 )
{
nt = 1, y = 0, z = 0;
try
{
z = / y;
Sy8te2.out.prntln( Not eecuted);
}
catch( cepton e )
{
Sy8te2.out.prntln( cepton!);
}
Sy8te2.out.prntln( /y = + z );
}
}
]ara Copyright 2001-2004 1om lunter
publc cla88 Ha8ceptonHandlng
{
publc 8tatc vod 2an( Strng[] arg8 )
{
nt = 1, y = 0, z = 0;
try
{
z = / y;
Sy8te2.out.prntln( Not eecuted);
}
catch( cepton e )
{
Sy8te2.out.prntln( cepton!);
}
Sy8te2.out.prntln( /y = + z );
}
}
Any code you think might
throw an exception should
be enclosed in a try`
block.
Lery try block must be paired with at least one
catch` block-oten more than one. 1he catch
block will be executed only only i an exception occurs.
\hen an exception
happens, the remainder
o the try block is
abandoned. Variables go
out o scope. No return
is possible.
]ara Copyright 2001-2004 1om lunter
publc cla88 Ha8ceptonHandlng
{
publc 8tatc vod 2an( Strng[] arg8 )
{
nt = 1, y = 0, z = 0;
try
{
z = / y;
}
catch( cepton e )
{
Sy8te2.out.prntln( cepton!);
}
Sy8te2.out.prntln( /y = + z );
}
}
1he Sequence:
i., A particular exception occurs.
ii., 1he runtime system generates
an exception object that matches
the exception that occurred.
iii., 1hen, the runtime system
goes looking or the nearest
catch block that can handle that that
speciic type o exception speciic type o exception.
I the nearest catch block doesn`t match the exception
that happened, the runtime looks beyond this method
or another catch block. But, in tbi. case, cepton
is the Superclass or all exceptions, so it always matches.
cepton!
/y = 0
]ara Copyright 2001-2004 1om lunter
publc cla88 Ha8ceptonHandlngWrongCatch
{
publc 8tatc vod 2an( Strng[] arg8 )
{
nt = 1, y = 0, z = 0;
try
{
z = / y;
}
catch( NullPontercepton e )
{
Sy8te2.out.prntln( cepton);
}
Sy8te2.out.prntln( /y = + z );
}
}
In tbi. tbi. case, howeer, the catch block is expecting a different ty5e
of exce5tion. So, tbi. tbi. catch block doesn`t catch the error. 1he
exception is NO1 caught. 1he program crashes. 1he next
statement ater the catch block is not executed.
]ara Copyright 2001-2004 1om lunter
publc cla88 Ha8ceptonHandlng
{
publc 8tatc vod 2an( Strng[] arg8 )
{
nt = 1, y = 0, z = 0;
try
{
z = / y;
}
catch( NullPontercepton npe )
{
Sy8te2.out.prntln( Null cepton!);
}
catch( DvdeByZerocepton dbze )
{
Sy8te2.out.prntln(
DvdeByZerocepton! + dbze.toStrng() );
}
Sy8te2.out.prntln( Whoop8! );
}
}
1his one doesn`t
match, so it is skipped.
1his one aoe. aoe. match, so
it i. i. executed.
Since the exception was caught, execution can resume.
]ara Copyright 2001-2004 1om lunter
Usually, many statements in your try block can
cause exceptions and-since you can`t predict
which one will pop-you place seeral dierent
catch blocks ater your one try block.
1he most speciic catch blocks should be
listed irst irst and the generic cepton ,rbicb i.
tbe $vercta.. to att ecetiov., should be listed last last.
14.4 The Basics oI Java Exception Handling
]ara Copyright 2001-2004 1om lunter
1his whole process is known as the:
1ermination model 1ermination model o exception handling.`
14.4 The Basics oI Java Exception Handling: term
1he place where the exception occurred is the
throw point throw point.
Ater an exception has occurred, execution
abandons the try block abandons the try block rom the throw point on.
\e say the block that threw the exception
expires expires.
]ara Copyright 2001-2004 1om lunter
1he
1nally
Block
]ara Copyright 2001-2004 1om lunter
The 1nally Block
Jaa exception handling oers a third
otiovat otiovat twist on the try-catch block:
1he 1nally block oers you a place to
put code that must always be executed no no
matter what matter what-exception or no exception.
Remember: i you use a try, then you
vv.t vv.t use a catch .
1he 1nally is otiovat otiovat .
]ara Copyright 2001-2004 1om lunter
1he 1nally block is like the
Maia Maia-i you inite it in your code,
it`s there whether you end up needing
it or not.
So, i your try block works perectly-then
the code in the 1nally block gets executed.
And. i your try block tbror. av ecetiov
and the catch block catcbe. tbe ecetiov-then
the code in the 1nally block still still gets
executed.
The 1nally Block
]ara Copyright 2001-2004 1om lunter
publc cla88 Ha8nallyBlock%oo
{
publc 8tatc vod 2an( Strng[] arg8 )
{
nt = 1, y = 0, z = 0;
try
{
z = / y;
}
catch( NullPontercepton e )
{
Sy8te2.out.prntln( cepton);
}
1nally
{
Sy8te2.out.prntln( Alway8!);
}
}
}
Always, Always Always executes!
]ara Copyright 2001-2004 1om lunter
1he try Block:
A Net Oer a
Rabbit lole
]ara Copyright 2001-2004 1om lunter
Net Over a Rabbit Hole
Obiously, a try block can catch an exception
in the method where it`s located.
But, a try block can at.o at.o catch an exception far far
revorea revorea rom the method where it`s located-as
long as no other block in between catches it irst.
]ara Copyright 2001-2004 1om lunter
publc cla88 GenercceptonHandlng
{
publc 8tatc vod 2an( Strng[] arg8 )
{
try
{
// ecepton XYZ
}
catch( XYZ e )
{
Sy8te2.out.prntln( XYZ Happened);
}
}
}
1his is routine exception handling,
which should now be amiliar.
]ara Copyright 2001-2004 1om lunter
publc cla88 Catche8D8tantcepton
{
publc 8tatc vod 2an( Strng[] arg8 )
{
try
{
MyCla88 to2 = new MyCla88();
to2.cau8e8cepton();
}
catch( XYZ e )
{
Sy8te2.out.prntln( XYZ Happened);
}
}
}
As long as our catch block is the irst one to be
encountered, it will catch XYZ exception thrown
deep inside o to2.cau8e8cepton();
]ara Copyright 2001-2004 1om lunter
Net Over a Rabbit Hole
Now, we will see a more complex example o the
preious example.
\e will show how a method call ar down the
method stack can:
-throw an exception and
-propagate the exception back up the call
stack in search o a handler.
]ara Copyright 2001-2004 1om lunter
publc cla88 Acepton
{
publc Acepton()
{
Sy8te2.out.prntln( "Cn8t: Acepton" );
Bcepton be = new Bcepton();
}
publc 8tatc vod 2an(Strng[] arg8)
{
Acepton ae = new Acepton();
}
}
publc cla88 Bcepton
{
publc Bcepton()
{
Sy8te2.out.prntln( "Cn8t: Bcepton" );
Ccepton ce = new Ccepton();
try
{
ce.populateArray();
}
catch( ArrayIndeOutO1Bound8cepton e )
{
//do 8o2ethng
}
}
}
1he pink pink arrow will stay
and wait, to illustrate that
this method has not yet
inished executing. It has
opened another method
in the call stack.
Now, the burgundy burgundy arrow
will wait with the pink arrow,
to show that now two
methods are stacked` up
,in the stack, waiting or the
execution o their methods
to conclude.
Acepton.2an()
Acepton
Now, the red red arrow will
stay and wait, to illustrate
that this method has not
yet inished executing. It
has opened yet another
method in the call stack.
Bcepton
]ara Copyright 2001-2004 1om lunter
publc cla88 Ccepton
{
nt[] ntArray = new nt[3];
publc Ccepton()
{
Sy8te2.out.prntln( "Cn8t: Ccepton" );
}
publc vod populateArray() throw8 ArrayIndeOutO1Bound8cepton
{
ntArray[0] = 100;
ntArray[1] = 101;
ntArray[2] = 102;
ntArray[3] = 103;
}
}
Acepton.2an()
Acepton
Bcepton
1hese are the method
calls rom the other
classes still waiting.
]ara Copyright 2001-2004 1om lunter
publc cla88 Bcepton
{
publc Bcepton()
{
Sy8te2.out.prntln( "Cn8t: Bcepton" );
Ccepton ce = new Ccepton();
try
{
ce.populateArray();
}
catch( ArrayIndeOutO1Bound8cepton e )
{
//do 8o2ethng
}
}
}
publc cla88 Acepton
{
publc Acepton()
{
Sy8te2.out.prntln( "Cn8t: Acepton" );
Bcepton be = new Bcepton();
}
publc 8tatc vod 2an(Strng[] arg8)
{
Acepton ae = new Acepton();
}
}
Acepton.2an()
Acepton
Bcepton
Since the red on8tructor
method o Ccepton
inished, this line in the
stack trace goes away.
Now, in the try block, we go
back to the instance o class
Ccepton we just
instantiated to execute its
method populateArray()
]ara Copyright 2001-2004 1om lunter
publc cla88 Ccepton
{
nt[] ntArray = new nt[3];
publc Ccepton()
{
Sy8te2.out.prntln( "Cn8t: Ccepton" );
}
publc vod populateArray() throw8 ArrayIndeOutO1Bound8cepton
{
ntArray[0] = 100;
ntArray[1] = 101;
ntArray[2] = 102;
ntArray[3] = 103;
}
}
Acepton.2an()
Acepton
1hese are the method
calls rom the other
classes still waiting.
100 101 102
ArrayIndeOutO1Bound8cepton !
]ara Copyright 2001-2004 1om lunter
publc cla88 Bcepton
{
publc Bcepton()
{
Sy8te2.out.prntln( "Cn8t: Bcepton" );
Ccepton ce = new Ccepton();
try
{
ce.populateArray();
}
catch( ArrayIndeOutO1Bound8cepton e )
{
//do 8o2ethng
}
}
}
publc cla88 Acepton
{
publc Acepton()
{
Sy8te2.out.prntln( "Cn8t: Acepton" );
Bcepton be = new Bcepton();
}
publc 8tatc vod 2an(Strng[] arg8)
{
Acepton ae = new Acepton();
}
}
Acepton.2an()
Acepton
Since the try block
threw an exception,
when we propagate out
o the called method,
the JVM immediately
looks or an appropriate
catch block.
Ater the thrown
exception has been
successully caught, the
Bcepton()
constructor can inish.
]ara Copyright 2001-2004 1om lunter
publc cla88 Acepton
{
publc Acepton()
{
Sy8te2.out.prntln( "Cn8t: Acepton" );
Bcepton be = new Bcepton();
}
publc 8tatc vod 2an(Strng[] arg8)
{
Acepton ae = new Acepton();
}
}
Acepton.2an()
And lastly, the
Acepton that
started it all can inish
and we`re back where we
started.
s
Cn8t: Acepton
Cn8t: Bcepton
Cn8t: Ccepton
cepton: ArrayIndeOutO1Bound8cepton
A1ter 2ethod populateArray()
]ara Copyright 2001-2004 1om lunter
Adisory: although we used the Runt2ecepton
ArrayIndeOutO1Bound8cepton or this example, in act
this is one you should preent through good old ashioned bounds
checking, rather than allowing it to throw an exception.
Still, it makes or a good example.
]ara Copyright 2001-2004 1om lunter
Lxception
landling:
Limitations
]ara Copyright 2001-2004 1om lunter
Lxception-handling can only
cope with synchronous errors-
ones that occur in the execution
step as it is currently being
executed.
Exception Handling: Limitations
]ara Copyright 2001-2004 1om lunter
Exception Handling: Limitations
Lxception landling is
vot vot able to cope with
asynchronous errors-
ones that only become
apparent ater a period o
waiting, such as while
waiting or a disk I,O
read to happen.
]ara Copyright 2001-2004 1om lunter
Parsing
the
Lxception Object
]ara Copyright 2001-2004 1om lunter
!arsing the Exception Object
In your catch block, it is customary to inspect
and utilize the inormation about the exception
contained in the cepton object.
]ara Copyright 2001-2004 1om lunter

try
{
//8o2ethng bad happen8 here
}
catch( NullPontercepton e )
{
Sy8te2.out.prntln( NullPontercepton +
e.toStrng() );
}
\hen the runtime system creates the exception
object, the reerence ,here named e`, contains
eerything that is known about the exception. By
using its toStrng() method, we reeal that
inormation.
]ara Copyright 2001-2004 1om lunter
Exception Handling
Aboe all, Lxception landling is an opportunity
to do something-it gies you the chance to
interene, but it is up to ,ov ,ov to plan what happens
when a speciic exception is thrown.
]ara Copyright 2001-2004 1om lunter

try
{
//8o2ethng bad happen8 here
}
catch( cepton e )
{
}
\hat hae we done here
Deeated 1he Lxception
landling Mechanism! 1he
program will resume executing as
i no exception occurred!
]ara Copyright 2001-2004 1om lunter
Exception Handling
In a console program-one that runs in the DOS
window or UNIX shell-an unhandled exception
results in the program terminating.
A GUI program can go on executing een ater an
unhandled exception-but producing incorrect and
unpredictable results in the process.
Moral o the Story
In a GUI program-be especially especially careul to
handle your errors intelligently.
]ara Copyright 2001-2004 1om lunter
1he
Causes
o
Lxceptions
]ara Copyright 2001-2004 1om lunter
The Causes oI Exceptions
An Lxception is 1hrown or One o 1hree Reasons:
1.-An abnormal execution condition was synchronously
detected by the Jaa Virtual Machine.
Possible Causes:
-Laluation o an expression iolates the rules o the
Jaa Language, such as an integer diide by zero, etc.
-An error occurs in loading or linking the Jaa program.
-Some limitation in a resource is exceeded, such as
using too much memory.
]ara Copyright 2001-2004 1om lunter
The Causes oI Exceptions
An Lxception is 1hrown or One o 1hree Reasons:
2.-A throw statement was executed in Jaa code
Possible Causes:
-1he program execution met an error that had been
expected.
]ara Copyright 2001-2004 1om lunter
The Causes oI Exceptions
An Lxception is 1hrown or One o 1hree Reasons:
3.-An asynchronous exception occurred.
Possible Causes:
-1he method 8top() o class %hread was inoked.
-An internal error has occurred in the irtual machine.
]ara Copyright 2001-2004 1om lunter
low to re re throw
our Own
Lxceptions
]ara Copyright 2001-2004 1om lunter
How to re re- -throw our Own Exceptions
Usually, the JVM decides when to throw an
exception.
But, the programmer hersel can choose when to
throw an exception.
Also, i your catch block handles an exception but
then decides it really can`t handle it decides it really can`t handle it, you can include
logic in your catch block to re re--throw the exception throw the exception to
a handler higher up in the call stack.
]ara Copyright 2001-2004 1om lunter
try
{
// So2e proce88ng hereno ecepton though
try
{
// a Doodlebugcepton occur8 here.
}
catch( Doodlebugcepton e )
{
// 8o2e ecepton proce88ng...
Sy8te2.out.prntln( Doodlebug ecepton );
throw new Bugcepton();
}
}
catch( Bugcepton e )
{
Sy8te2.out.prntln( Bugcepton! +
e.toStrng() );
}
lirstly, we are within the blue try block.
Ater some ok processing, we`re in the red try block.
\e`re able to do
logic in the catch
block, but or some
reason, the
programmer
thought it was
necessary to rethrow rethrow
the exception object
e`
Ater the rethrow, the exception is handled by the
nearest enclosing enclosing catch block that is able to handle it.
]ara Copyright 2001-2004 1om lunter
How to re re- -throw our Own Exceptions
A method is not permitted to throw an exception
o its own unless you speciy in the method signature
which speciic Lxceptions it throws.
]ara Copyright 2001-2004 1om lunter
Compile-1ime
Checking
o
Lxceptions
]ara Copyright 2001-2004 1om lunter
Compile-Time Checking oI Exceptions
I a method or constructor method
announces that it has the ability to throw a
certain type o exception, then the compiler
checks to see i there are exception handlers in
place to deal with those announced exceptions.
1he throws clause or the method must mention
the class o that exception, or one o the
Superclasses o the exception that the method can
throw.
]ara Copyright 2001-2004 1om lunter
Compile-Time Checking oI Exceptions
Lxceptions that are explicitly announced as
being possible by methods or constructors are
known as...
checked exceptions.`
]ara Copyright 2001-2004 1om lunter
Compile-Time Checking oI Exceptions
1he otber kinds o exceptions are known as
vvchecked exceptions.`
1hese come rom the class Runt2ecepton
and its subclasses, and rom the class rror and its
subclasses.
All other exception classes are checked exception
classes.
]ara Copyright 2001-2004 1om lunter
Compile-Time Checking oI Exceptions
\hy Lrrors are not checked:
rror and its subclasses are exempt
rom compile-time checking because they are
unpredictable.
1hey can occur anywhere so it would
needlessly clutter up your program i you
attempted to catch them.
Also, more importantly, no recoery is
eer possible rom an rror .
]ara Copyright 2001-2004 1om lunter
Compile-Time Checking oI Exceptions
\hy RuntimeLxceptions are not checked:
1hese problems are usually beyond the
programmer`s control. 1hus, it would be a
needless irritation to the programmer i she was
orced to catch these.
]ara Copyright 2001-2004 1om lunter
publc cla88 %e8tcepton
{
publc 8tatc vod 2an( Strng[] arg8 )
{
nt[] a = new nt[2];
a[0] = 1;
a[1] = 2;
a[3] = 3;
Sy8te2.out.prntln( Array a[2]= + a[2] );
}
}
As you can see, this 2an method
is ripe or an exception. And, as
expected, when we execute it, we
will see the ollowing:
]ara Copyright 2001-2004 1om lunter
1he JVM encountered an
uncaught exception.
1his was where the JVM was when it
met the uncaught exception.
]ara Copyright 2001-2004 1om lunter
publc 8tatc vod 2an( Strng[] arg8 )
{
nt[] a = new nt[2];
try
{
a[0] = 1;
a[1] = 2;
a[2] = 3;
Sy8te2.out.prntln( "Array a[2]=" + a[2] );
}
catch( ArrayIndeOutO1Bound8cepton e )
{
Sy8te2.out.prntln( "Do 8o2ethng here" + e );
}
}
1his is our array. It has
two slots aailable.
1his statement will attempt to use a
non-existent 3rd slot in our array.
]ara Copyright 2001-2004 1om lunter
]ara Copyright 2001-2004 1om lunter
Clicking on the e` exception
object, we see exactly the kind
that was thrown.
]ara Copyright 2001-2004 1om lunter
1he Stack Dump:
\hen our
catch
Misses
]ara Copyright 2001-2004 1om lunter
The Stack Dump
I an unexpected exception occurs, then your
careully-planned catch block will ail to capture the
exception.
In this case, your console will ill with a stack dump:
041.453 1024 HttpTransport X IJ.Error
java.net.SocketException: Connection reset by peer
java.lang.Throwable(java.lang.String)
java.lang.Exception(java.lang.String)
java.io.IJException(java.lang.String)
java.net.SocketException(java.lang.String)
void java.net.SocketJutputStream.socketWrite(byte ,, int, int)
void java.net.SocketJutputStream.write(byte ,, int, int)
void com.ibm.servlet.engine.http_transport.HttpTransportConnection.write(byte ,, int, int)
void com.ibm.servlet.engine.http_transport.HttpTransportConnection.prepareForWrite(int, java.lang.String, java.lang.String ,)
void com.ibm.servlet.engine.srp.SRPConnection.prepareForWrite(int, java.lang.String, java.lang.String ,, java.lang.String ,)
void com.ibm.servlet.engine.srt.SRTServletResponse.commit()
void com.ibm.servlet.engine.srt.SRTServletResponse.alertFirstWrite()
void com.ibm.servlet.engine.srt.SRTJutputStream.write(byte ,, int, int)
void java.io.JutputStreamWriter.write(char ,, int, int)
void java.io.PrintWriter.write(char ,, int, int)
void com.ibm.servlet.engine.webapp.BufferedWriter.writeJut(char ,, int, int)
void com.ibm.servlet.engine.webapp.BufferedWriter.write(char ,, int, int)
void java.io.PrintWriter.write(char ,, int, int)
void com.sun.jsp.runtime.JspWriterImpl.flushBuffer()

Das könnte Ihnen auch gefallen