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.marshall;
018
019import static org.apache.juneau.commons.utils.Shorts.*;
020
021/**
022 * An exception that typically occurs when trying to perform an invalid operation on a configuration property.
023 *
024 * @serial exclude
025 */
026@SuppressWarnings({
027   "java:S110" // Deep inheritance inherent to the exception hierarchy
028})
029public class ConfigException extends BasicRuntimeException {
030   private static final long serialVersionUID = 1L;
031
032   /**
033    * Constructor
034    *
035    * @param message The error message.
036    * @param args Optional {@link String#format(String, Object...) String.format}-style arguments.
037    */
038   public ConfigException(String message, Object...args) {
039      this(null, message, args);
040   }
041
042   /**
043    * Constructor.
044    *
045    * @param cause The cause of this exception.  Can be <jk>null</jk> (no cause is set).
046    * @param message The {@link String#format(String, Object...) String.format}-style message (<c>%s</c> placeholders).
047    * @param args Optional {@link String#format(String, Object...) String.format}-style arguments.
048    */
049   public ConfigException(Throwable cause, String message, Object...args) {
050      super(cause, message, args);
051   }
052
053   @Override
054   public String getMessage() {
055      Throwable t = getCause();
056      if (t == null)
057         return super.getMessage();
058      var sb = new StringBuilder(super.getMessage());
059      while (nn(t)) {
060         sb.append("  ").append(t.getMessage());
061         t = t.getCause();
062      }
063      return sb.toString();
064   }
065
066   @Override /* Overridden from BasicRuntimeException */
067   public ConfigException setMessage(String message, Object...args) {
068      super.setMessage(message, args);
069      return this;
070   }
071}