View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau;
18  
19  import static org.apache.juneau.commons.utils.Utils.*;
20  
21  import java.text.*;
22  
23  /**
24   * Subclass of runtime exceptions that take in a message and zero or more arguments.
25   *
26   *
27   * @serial exclude
28   */
29  public class BasicRuntimeException extends RuntimeException {
30  	private static final long serialVersionUID = 1L;
31  	boolean unmodifiable;
32  	String message;
33  
34  	/**
35  	 * Constructor.
36  	 *
37  	 * @param message The {@link MessageFormat}-style message.
38  	 * @param args Optional {@link MessageFormat}-style arguments.
39  	 */
40  	public BasicRuntimeException(String message, Object...args) {
41  		super(f(message, args));
42  	}
43  
44  	/**
45  	 * Constructor.
46  	 *
47  	 * @param cause The cause of this exception.
48  	 */
49  	public BasicRuntimeException(Throwable cause) {
50  		super(cause);
51  	}
52  
53  	/**
54  	 * Constructor.
55  	 *
56  	 * @param cause The cause of this exception.
57  	 * @param message The {@link MessageFormat}-style message.
58  	 * @param args Optional {@link MessageFormat}-style arguments.
59  	 */
60  	public BasicRuntimeException(Throwable cause, String message, Object...args) {
61  		super(f(message, args), cause);
62  	}
63  
64  	@Override /* Overridden from Throwable */
65  	public String getMessage() {
66  		return nn(message) ? message : super.getMessage();
67  	}
68  
69  	/**
70  	 * Sets the detail message on this exception.
71  	 *
72  	 * @param message The message.
73  	 * @param args The message args.
74  	 * @return This object.
75  	 */
76  	public BasicRuntimeException setMessage(String message, Object...args) {
77  		this.message = f(message, args);
78  		return this;
79  	}
80  }