001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel;
018
019/**
020 * Base class for all Camel unchecked exceptions.
021 */
022public class RuntimeCamelException extends RuntimeException {
023    private static final long serialVersionUID = 8046489554418284257L;
024
025    public RuntimeCamelException() {
026    }
027
028    public RuntimeCamelException(String message) {
029        super(message);
030    }
031
032    public RuntimeCamelException(String message, Throwable cause) {
033        super(message, cause);
034    }
035
036    public RuntimeCamelException(Throwable cause) {
037        super(cause);
038    }
039
040    /**
041     * Wraps the caused exception in a {@link RuntimeCamelException} if its not
042     * already such an exception.
043     *
044     * @param e the caused exception
045     * @return the wrapper exception
046     */
047    public static RuntimeCamelException wrapRuntimeCamelException(Throwable e) {
048        if (e instanceof RuntimeCamelException) {
049            // don't double wrap
050            return (RuntimeCamelException) e;
051        } else {
052            return new RuntimeCamelException(e);
053        }
054    }
055
056    /**
057     * Wraps the caused exception in a {@link RuntimeCamelException} if its not
058     * already a runtime exception.
059     *
060     * @param e the caused exception
061     * @return the wrapper exception
062     */
063    public static RuntimeException wrapRuntimeException(Throwable e) {
064        if (e instanceof RuntimeException) {
065            // don't double wrap
066            return (RuntimeException) e;
067        } else {
068            return new RuntimeCamelException(e);
069        }
070    }
071}