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 * General bean runtime operation exception. 019 * 020 * <h5 class='section'>See Also:</h5><ul> 021 022 * </ul> 023 * 024 * @serial exclude 025 */ 026public final class BeanRuntimeException extends BasicRuntimeException { 027 028 private static final long serialVersionUID = 1L; 029 030 /** 031 * Constructor. 032 * 033 * @param cause The cause of this exception. 034 * @param c The class name of the bean that caused the exception. 035 * @param message The {@link MessageFormat}-style message. 036 * @param args Optional {@link MessageFormat}-style arguments. 037 */ 038 public BeanRuntimeException(Throwable cause, Class<?> c, String message, Object... args) { 039 super(cause, getMessage(cause, c, message), args); 040 } 041 042 /** 043 * Constructor. 044 * 045 * @param message The error message. 046 */ 047 public BeanRuntimeException(String message) { 048 this((Throwable)null, null, message); 049 } 050 051 /** 052 * Constructor. 053 * 054 * @param message The error message. 055 * @param args Arguments passed in to the {@code String.format()} method. 056 */ 057 public BeanRuntimeException(String message, Object...args) { 058 this(null, null, message, args); 059 } 060 061 /** 062 * Constructor. 063 * 064 * @param c The class name of the bean that caused the exception. 065 * @param message The error message. 066 * @param args Arguments passed in to the {@code String.format()} method. 067 */ 068 public BeanRuntimeException(Class<?> c, String message, Object... args) { 069 this(null, c, message, args); 070 } 071 072 /** 073 * Constructor. 074 * 075 * @param cause The initial cause of the exception. 076 */ 077 public BeanRuntimeException(Throwable cause) { 078 this(cause, null, null); 079 } 080 081 private static String getMessage(Throwable cause, Class<?> c, String msg) { 082 if (msg != null) 083 return (c == null ? "" : c.getName() + ": ") + msg; 084 if (cause != null) 085 return (c == null ? "" : c.getName() + ": ") + cause.getMessage(); 086 return null; 087 } 088}