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
015/**
016 * General bean runtime operation exception.
017 */
018public final class BeanRuntimeException extends FormattedRuntimeException {
019
020   private static final long serialVersionUID = 1L;
021
022   /**
023    * Constructor.
024    * 
025    * @param message The error message.
026    */
027   public BeanRuntimeException(String message) {
028      super(message);
029   }
030
031   /**
032    * Constructor.
033    * 
034    * @param message The error message.
035    * @param args Arguments passed in to the {@code String.format()} method.
036    */
037   public BeanRuntimeException(String message, Object...args) {
038      super(message, args);
039   }
040
041   /**
042    * Shortcut for calling <code><jk>new</jk> BeanRuntimeException(String.format(c.getName() + <js>": "</js> + message, args));</code>
043    * 
044    * @param c The class name of the bean that caused the exception.
045    * @param message The error message.
046    * @param args Arguments passed in to the {@code String.format()} method.
047    */
048   public BeanRuntimeException(Class<?> c, String message, Object... args) {
049      super(c.getName() + ": " + message, args);
050   }
051
052   /**
053    * Constructor.
054    * 
055    * @param cause The initial cause of the exception.
056    */
057   public BeanRuntimeException(Throwable cause) {
058      super(cause == null ? null : cause.getLocalizedMessage());
059      initCause(cause);
060   }
061
062   /**
063    * Sets the inner cause for this exception.
064    * 
065    * @param cause The inner cause.
066    * @return This object (for method chaining).
067    */
068   @Override /* Throwable */
069   public synchronized BeanRuntimeException initCause(Throwable cause) {
070      super.initCause(cause);
071      return this;
072   }
073}