001
002 /*
003 * Copyright (C) 2011 Archie L. Cobbs. All rights reserved.
004 *
005 * $Id: CheckedExceptionWrapper.java 2 2011-02-05 21:51:43Z archie.cobbs $
006 */
007
008 package org.dellroad.stuff.java;
009
010 /**
011 * Wraps checked exceptions so they can be thrown across API methods that don't declare them.
012 */
013 @SuppressWarnings("serial")
014 public class CheckedExceptionWrapper extends RuntimeException {
015
016 private final Exception exception;
017
018 /**
019 * Constructor.
020 *
021 * @throws IllegalArgumentException if {@code exception} is {@code null}
022 */
023 public CheckedExceptionWrapper(Exception exception) {
024 if (exception == null)
025 throw new IllegalArgumentException("null exception");
026 this.exception = exception;
027 }
028
029 /**
030 * Get the wrapped exception.
031 */
032 public Exception getException() {
033 return this.exception;
034 }
035
036 /**
037 * Throw the wrapped exception.
038 */
039 public void throwException() throws Exception {
040 throw this.exception;
041 }
042 }
043