multex
Class Failure

java.lang.Object
  extended byjava.lang.Throwable
      extended byjava.lang.Exception
          extended byjava.lang.RuntimeException
              extended bymultex.Failure
All Implemented Interfaces:
MultexException, java.io.Serializable
Direct Known Subclasses:
AssertionFailure

public class Failure
extends java.lang.RuntimeException
implements MultexException

Indirectly caused exception with parameters, causal chain and internationalizable message text. This class serves for the framework user as a base class for defining Failure-exceptions. Objects of this class can be thrown, too, but such exceptions cannot be handled individually nor get internationalized. Failure-exceptions have the following benefits:

The (unnamed, indexed) exception parameters are handled the same way as in class Exc.

Naming convention: All user-defined exception classes derived from Failure should have a name ending in Failure. The pattern is:

      class OperationnameFailure extends Failure { ... }
    

Failure as unchecked exception?

It can be bothering always to specify Failure in the throws-clause of any method, that calls other non-trivial methods. This holds especially, when you are converting an existing software system to usage of MulTEx. Thus Failure inherits the unchecked java.lang.RuntimeException.

So you can specify Failure, but you need not to do this. This is in my opinion not the cleanest way, but even without Failure you could not base on the assumption, that a method without a throws-clause does not throw any exception. Any method could throw any java.lang.RuntimeException, e.g. the IndexOutOfBoundsException.

If you want to strictly check Failure, then you can change the superclass of Failure to the checked java.lang.Exception instead of the unchecked java.lang.RuntimeException. Up to now I am not sure, what is the best way. Please report your experiences.

Author:
Christoph Knabe, knabe@tfh-berlin.de, TFH Berlin, 1999-2005
See Also:
Serialized Form

Field Summary
static java.lang.String className
          The unqualified name of this class
 
Constructor Summary
Failure(java.lang.String i_defaultMessageTextPattern)
          Convenience constructor null null.
Failure(java.lang.String i_defaultMessageTextPattern, java.util.Collection i_parameters)
          Convenience constructor with parameters as Collection.
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause)
          Convenience constructor null
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0)
          Convenience constructor 0
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object[] i_parameters)
          Constructs a Failure-exception, giving complete diagnostic information.
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0, java.lang.Object i_object1)
          Convenience constructor 1
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0, java.lang.Object i_object1, java.lang.Object i_object2)
          Convenience constructor 2
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0, java.lang.Object i_object1, java.lang.Object i_object2, java.lang.Object i_object3)
          Convenience constructor 3
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0, java.lang.Object i_object1, java.lang.Object i_object2, java.lang.Object i_object3, java.lang.Object i_object4)
          Convenience constructor 4
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0, java.lang.Object i_object1, java.lang.Object i_object2, java.lang.Object i_object3, java.lang.Object i_object4, java.lang.Object i_object5)
          Convenience constructor 5
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0, java.lang.Object i_object1, java.lang.Object i_object2, java.lang.Object i_object3, java.lang.Object i_object4, java.lang.Object i_object5, java.lang.Object i_object6)
          Convenience constructor 6
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0, java.lang.Object i_object1, java.lang.Object i_object2, java.lang.Object i_object3, java.lang.Object i_object4, java.lang.Object i_object5, java.lang.Object i_object6, java.lang.Object i_object7)
          Convenience constructor 7
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0, java.lang.Object i_object1, java.lang.Object i_object2, java.lang.Object i_object3, java.lang.Object i_object4, java.lang.Object i_object5, java.lang.Object i_object6, java.lang.Object i_object7, java.lang.Object i_object8)
          Convenience constructor 8
Failure(java.lang.String i_defaultMessageTextPattern, java.lang.Throwable i_cause, java.lang.Object i_object0, java.lang.Object i_object1, java.lang.Object i_object2, java.lang.Object i_object3, java.lang.Object i_object4, java.lang.Object i_object5, java.lang.Object i_object6, java.lang.Object i_object7, java.lang.Object i_object8, java.lang.Object i_object9)
          Convenience constructor 9
Failure(java.lang.Throwable i_cause)
          Usable as
Method Summary
 java.lang.String getDefaultMessageTextPattern()
          Returns the default message text pattern for this exception object or null.
 java.lang.String getMessage()
          Returns all user-provided information contained in the exception object in an internal, but human readable format.
 java.lang.Object[] getParameters()
          Returns a copy of the positional exception parameter array, or null if the exception does not have parameters.
 boolean hasParameters()
          Returns true, if the exception parameter array exists and has at least one element.
 void printStackTrace()
          Prints the chained, compact stack traces of this Failure object to the standard error stream System.err.
 void printStackTrace(java.io.PrintStream io_printer)
          Prints the chained, compact stack traces of this Failure object to io_printer.
 void printStackTrace(java.io.PrintWriter io_printer)
          Prints the chained, compact stack traces of this Failure object to io_printer.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface multex.MultexException
getCause
 

Field Detail

className

public static final java.lang.String className
The unqualified name of this class

See Also:
Constant Field Values
Constructor Detail

Failure

public Failure(java.lang.Throwable i_cause)
Usable as Tunneling Exception. When reporting the message chain, instances of multex.Failure without any own information, will be suppressed by method Msg.printMessages(StringBuffer,Throwable,ResourceBundle) and the similar convenience methods. This is a convenience constructor with only a cause, but null for both i_defaultMessageTextPattern, and i_parameters.

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern)
Convenience constructor null null. Gives only a message text without cause and parameters. As it has no parameters, the message text pattern will be reported unchanged.

Since:
MulTEx 7.1 at 2006-11-04
See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause)
Convenience constructor null

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0)
Convenience constructor 0

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0,
               java.lang.Object i_object1)
Convenience constructor 1

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0,
               java.lang.Object i_object1,
               java.lang.Object i_object2)
Convenience constructor 2

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0,
               java.lang.Object i_object1,
               java.lang.Object i_object2,
               java.lang.Object i_object3)
Convenience constructor 3

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0,
               java.lang.Object i_object1,
               java.lang.Object i_object2,
               java.lang.Object i_object3,
               java.lang.Object i_object4)
Convenience constructor 4

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0,
               java.lang.Object i_object1,
               java.lang.Object i_object2,
               java.lang.Object i_object3,
               java.lang.Object i_object4,
               java.lang.Object i_object5)
Convenience constructor 5

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0,
               java.lang.Object i_object1,
               java.lang.Object i_object2,
               java.lang.Object i_object3,
               java.lang.Object i_object4,
               java.lang.Object i_object5,
               java.lang.Object i_object6)
Convenience constructor 6

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0,
               java.lang.Object i_object1,
               java.lang.Object i_object2,
               java.lang.Object i_object3,
               java.lang.Object i_object4,
               java.lang.Object i_object5,
               java.lang.Object i_object6,
               java.lang.Object i_object7)
Convenience constructor 7

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0,
               java.lang.Object i_object1,
               java.lang.Object i_object2,
               java.lang.Object i_object3,
               java.lang.Object i_object4,
               java.lang.Object i_object5,
               java.lang.Object i_object6,
               java.lang.Object i_object7,
               java.lang.Object i_object8)
Convenience constructor 8

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object i_object0,
               java.lang.Object i_object1,
               java.lang.Object i_object2,
               java.lang.Object i_object3,
               java.lang.Object i_object4,
               java.lang.Object i_object5,
               java.lang.Object i_object6,
               java.lang.Object i_object7,
               java.lang.Object i_object8,
               java.lang.Object i_object9)
Convenience constructor 9

See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.util.Collection i_parameters)
Convenience constructor with parameters as Collection. You can use this as a List Failure, passing collected Throwables to i_parameters.

Since:
MulTEx 7
See Also:
Failure(String, Throwable, Object[])

Failure

public Failure(java.lang.String i_defaultMessageTextPattern,
               java.lang.Throwable i_cause,
               java.lang.Object[] i_parameters)
Constructs a Failure-exception, giving complete diagnostic information.

Example of defining an exception with default text, cause and parameters:

   public static class CopyFailure extends Failure {
     public CopyFailure(
       final Throwable i_cause,
       final String    i_inFileName,
       final String    i_outFileName
     ){
       super("File ''{0}'' could not be copied to ''{1}''",
         i_cause, new Object[]{i_inFileName, i_outFileName}
       );
     }
   }//CopyFailure
 
Instead of creating an Object[] yourself you can use the corresponding convenience constructors.

Parameters:
i_defaultMessageTextPattern - The default message text pattern in the syntax of java.text.MessageFormat or null, if message text pattern shall only be taken from a ResourceBundle using the class name as key.
i_cause - The causing Throwable object for providing the diagnostics causer chain. null is allowed here, if no cause is available or necessary.
i_parameters - Exception parameters as a polymorphic Object[], which can be inserted into the message text pattern by placeholders {0} ... {9}. null is allowed here, if you do not want to provide exception parameters.
Method Detail

getDefaultMessageTextPattern

public java.lang.String getDefaultMessageTextPattern()
Description copied from interface: MultexException
Returns the default message text pattern for this exception object or null. Inserting the exception parameters into the message text pattern is done by class MsgText. Locale specific message text patterns are handled by MsgText, too.

Specified by:
getDefaultMessageTextPattern in interface MultexException

hasParameters

public boolean hasParameters()
Description copied from interface: MultexException
Returns true, if the exception parameter array exists and has at least one element.

Specified by:
hasParameters in interface MultexException

getParameters

public java.lang.Object[] getParameters()
Description copied from interface: MultexException
Returns a copy of the positional exception parameter array, or null if the exception does not have parameters.

Specified by:
getParameters in interface MultexException

getMessage

public java.lang.String getMessage()
Description copied from interface: MultexException
Returns all user-provided information contained in the exception object in an internal, but human readable format. The information are the default message text pattern and the exception parameters of this object or null if none of these is provided. E.g.:
Unable to create file {0} in directory {1}
    {0}='myfile.dat'
    {1}='C:\temp\data'
  
Overrides the same method of java.lang.Throwable

Specified by:
getMessage in interface MultexException

printStackTrace

public void printStackTrace()
Prints the chained, compact stack traces of this Failure object to the standard error stream System.err.

See Also:
printStackTrace(java.io.PrintWriter)

printStackTrace

public void printStackTrace(java.io.PrintStream io_printer)
Prints the chained, compact stack traces of this Failure object to io_printer.

See Also:
printStackTrace(java.io.PrintWriter)

printStackTrace

public void printStackTrace(java.io.PrintWriter io_printer)
Prints the chained, compact stack traces of this Failure object to io_printer.