ExceptionContainer.java :  » Testing » UISpec4J » org » uispec4j » utils » Java Open Source

Java Open Source » Testing » UISpec4J 
UISpec4J » org » uispec4j » utils » ExceptionContainer.java
package org.uispec4j.utils;

public class ExceptionContainer {
  private RuntimeException exception;
  private Error error;

  public void set(Throwable e) {
    if (e instanceof RuntimeException) {
      exception = (RuntimeException)e;
    }
    else if (e instanceof Error) {
      error = (Error)e;
    }
    else {
      exception = new RuntimeException(e);
    }
  }

  public boolean isSet() {
    return (exception != null) || (error != null);
  }

  public void rethrowIfNeeded() {
    try {
      if (error != null) {
        throw error;
      }
      if (exception != null) {
        throw exception;
      }
    }
    finally {
      reset();
    }
  }

  public void reset() {
    exception = null;
    error = null;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.