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