com.opensymphony.util
Class MultipartException

java.lang.Object
  extended byjava.lang.Throwable
      extended byjava.lang.Exception
          extended bycom.opensymphony.util.MultipartException
All Implemented Interfaces:
Serializable

public class MultipartException
extends Exception

Exception to encapsulate many exceptions.

Very conceptual example

 class MyException extends MultipartException {
   // No class body needed as overrides default constructor.
 }

 public void doStuff() {
   try {
     checkEverything();
     println("Everything went fine.");
   }
   catch (MultipartException error) {
     Iterator i = error.list();
     println("Failed:");
     while(i.hasNext()) {
       println(" - " + (String)i.next() );
     }
   }
 }

 private void checkEverything() throws MyException {
   MyException m = new MyException;
   // add some exceptions if methods don't check out.
   if ( !verifySomething() ) m.add("Something not verified");
   if ( !verifySomethingElse() ) m.add("Something else not verified");
   // also (just for fun), add an exception if another exception is called.
   try {
     someMethodThatThrowsAnException()
   }
   catch(SomeWeirdException e) {
     m.add(e)
   }
   // check if any exceptions have been added and re-throw in one go if they have.
   if (m.hasErrors()) throw m;
 }

 

Version:
$Revision: 1.1.1.1 $
Author:
Joe Walnes
See Also:
Exception, List, Serialized Form

Field Summary
protected  List errors
          List used internally to store Strings of error messages.
 
Constructor Summary
MultipartException()
          Default constructor.
 
Method Summary
 void add(String msg)
          Add an error message to the Exception.
 void add(Throwable exception)
          Add an Exception's error message to the Exception.
 String[] getArray()
          Return error msgs as String array.
 Iterator getIterator()
          Return Iterator of String error msgs.
 List getList()
          Return error msgs as List of Strings.
 boolean hasErrors()
          Check whether any errors have been added.
 Iterator list()
          Deprecated. Use getIterator() instead.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

errors

protected List errors
List used internally to store Strings of error messages.

Constructor Detail

MultipartException

public MultipartException()
Default constructor. Initialises internal list.

Method Detail

getArray

public String[] getArray()
Return error msgs as String array.


getIterator

public Iterator getIterator()
Return Iterator of String error msgs.


getList

public List getList()
Return error msgs as List of Strings.


add

public void add(String msg)
Add an error message to the Exception.

Parameters:
msg - Error message.

add

public void add(Throwable exception)
Add an Exception's error message to the Exception.

Parameters:
exception - Exception of which getMessage() is called to add the message.

hasErrors

public boolean hasErrors()
Check whether any errors have been added.


list

public Iterator list()
Deprecated. Use getIterator() instead.

Return Iterator of error msgs.

Returns:
Iterator of String representations of error message.

OSCore Project Page