Introduction
If you want to do exception handling correct this is a hard job.
PatternTesting-Exception wants to help you to do this job.
For this reason this AspectJ library provides:
-
Better exception handling:
-
PatternTesting-Exception wraps some exception (e.g. IOException)
and replaces the message by some more helpful message
(e.g. for a FileNotFoundException you get the missing file with
the full pathname).
-
For this feature you have to do nothing in your code - no
configuration, no annotation is needed.
-
Test support for exception handling:
-
You have problem to test your exception handling? Use a mock which
provokes the desired exception. A mock would be too complicated for
the test? You're welcome.
Use the ExceptionFactory together with the
@TestException annotation and you can control if and when an
exception should be thrown. You can control it even via JMX.
So you can watch how your program or web application would react on an
unexpected exception.
Better Exceptions
At the moment only the call of the following JDK classes are wrapped
to provide better exceptions:
- java.io.File (for IOExceptions)
- java.io.FileInputStream (for FileNotFoundExceptions)
- java.io.FileOutputStream (for FileNotFoundExceptions)
- java.io.RandomAccessFile (for FileNotFoundExceptions)
- java.net.Socket (for ConnectExceptions)
Are some classes missing (yes, of course)?
Tell it to the
patterntesting-user
mailing list or enter a
feature request.
Some examples
For an example take a look into PatternTesting-Samples:
-
patterntesting.sample.Bomb
-
This is a very primitive bomb which simulates a countdown.
It shows you how you can use the @TestException annotation.
If you'll start this program
you can provoke an InterruptedException via JMX.