01: package org.uispec4j.utils;
02:
03: public class ExceptionContainer {
04: private RuntimeException exception;
05: private Error error;
06:
07: public void set(Throwable e) {
08: if (e instanceof RuntimeException) {
09: exception = (RuntimeException) e;
10: } else if (e instanceof Error) {
11: error = (Error) e;
12: } else {
13: exception = new RuntimeException(e);
14: }
15: }
16:
17: public boolean isSet() {
18: return (exception != null) || (error != null);
19: }
20:
21: public void rethrowIfNeeded() {
22: try {
23: if (error != null) {
24: throw error;
25: }
26: if (exception != null) {
27: throw exception;
28: }
29: } finally {
30: reset();
31: }
32: }
33:
34: public void reset() {
35: exception = null;
36: error = null;
37: }
38: }
|