001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest;
014
015import static org.apache.juneau.internal.StringUtils.*;
016
017import java.text.*;
018
019import javax.servlet.*;
020
021import org.apache.juneau.internal.*;
022
023/**
024 * General exception thrown from {@link RestServlet} during construction or initialization.
025 */
026public class RestServletException extends ServletException {
027
028   private static final long serialVersionUID = 1L;
029
030   /**
031    * Constructor.
032    *
033    * @param message The detailed message.
034    * @param args Optional {@link MessageFormat}-style arguments.
035    */
036   public RestServletException(String message, Object...args) {
037      super(format(message, args));
038   }
039
040   /**
041    * Constructor.
042    * 
043    * @param cause The cause. 
044    * @param message The detailed message.
045    * @param args Optional {@link MessageFormat}-style arguments.
046    */
047   public RestServletException(Throwable cause, String message, Object...args) {
048      super(format(message, args), cause);
049   }
050
051   /**
052    * Similar to {@link #getCause()} but searches until it finds the throwable of the specified type.
053    *
054    * @param <T> The throwable type.
055    * @param c The throwable type.
056    * @return The cause of the specified type, or <jk>null</jk> of not found.
057    */
058   public <T extends Throwable> T getCause(Class<T> c) {
059      return ThrowableUtils.getCause(c, this);
060   }
061}