1 /** 2 * Copyright 2008 Bryan Ray 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package uk.org.bryanray.testtoys.util; 17 18 /** 19 * <DL> 20 * <DT><B>Project:</B></DT> 21 * <DD>TestDataLoader</DD> 22 * <DT><B>Filename:</B></DT> 23 * <DD>ExceptionUtil.java</DD> 24 * <DT><B>Creation Date:</B></DT> 25 * <DD>26 May 2008</DD> 26 * </DL> 27 * 28 * @author Bryan Ray 29 */ 30 public class ExceptionUtil { 31 /** 32 * If the supplied exception is not a {@link RuntimeException}, the 33 * exception is converted to a {@link RuntimeException}, otherwise the 34 * exception is returned. 35 * 36 * @param exception 37 * The exception to convert to a {@link RuntimeException}. 38 */ 39 public static RuntimeException convertException(Exception exception) { 40 if (exception instanceof RuntimeException) { 41 return (RuntimeException) exception; 42 } else { 43 RuntimeException runtimeException = new RuntimeException(exception); 44 runtimeException.setStackTrace(exception.getStackTrace()); 45 return runtimeException; 46 } 47 } 48 }