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;
014
015import java.text.*;
016
017/**
018 * An exception that typically occurs when trying to perform an invalid operation on a configuration property.
019 */
020public class ConfigException extends FormattedRuntimeException {
021   private static final long serialVersionUID = 1L;
022
023   /**
024    * Constructor.
025    *
026    * @param cause The cause of this exception.
027    * @param message The {@link MessageFormat}-style message.
028    * @param args Optional {@link MessageFormat}-style arguments.
029    */
030   public ConfigException(Throwable cause, String message, Object... args) {
031      super(cause, getMessage(cause, message, null), args);
032   }
033
034   /**
035    * Constructor
036    *
037    * @param message The error message.
038    * @param args Optional {@link MessageFormat}-style arguments.
039    */
040   public ConfigException(String message, Object...args) {
041      this(null, message, args);
042   }
043
044   @Override
045   public String getMessage() {
046      Throwable t = getCause();
047      if (t == null)
048         return super.getMessage();
049      StringBuilder sb = new StringBuilder(super.getMessage());
050      while (t != null) {
051         sb.append("  ").append(t.getMessage());
052         t = t.getCause();
053      }
054      return sb.toString();
055   }
056}