public class MultipartException
extends java.lang.Exception
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;
}
Exception,
List,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected java.util.List |
errors
List used internally to store Strings of error messages.
|
| Constructor and Description |
|---|
MultipartException()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.lang.String msg)
Add an error message to the Exception.
|
void |
add(java.lang.Throwable exception)
Add an Exception's error message to the Exception.
|
java.lang.String[] |
getArray()
Return error msgs as String array.
|
java.util.Iterator |
getIterator()
Return Iterator of String error msgs.
|
java.util.List |
getList()
Return error msgs as List of Strings.
|
boolean |
hasErrors()
Check whether any errors have been added.
|
java.util.Iterator |
list()
Deprecated.
Use getIterator() instead.
|
protected java.util.List errors
public MultipartException()
public java.lang.String[] getArray()
public java.util.Iterator getIterator()
public java.util.List getList()
public void add(java.lang.String msg)
msg - Error message.public void add(java.lang.Throwable exception)
exception - Exception of which getMessage() is called to add the message.public boolean hasErrors()
public java.util.Iterator list()
String representations of error message.