1 /*
2 * Copyright 2002-2012 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.springframework.beans;
18
19 import org.springframework.core.NestedRuntimeException;
20 import org.springframework.util.ObjectUtils;
21
22 /**
23 * Abstract superclass for all exceptions thrown in the beans package
24 * and subpackages.
25 *
26 * <p>Note that this is a runtime (unchecked) exception. Beans exceptions
27 * are usually fatal; there is no reason for them to be checked.
28 *
29 * @author Rod Johnson
30 * @author Juergen Hoeller
31 */
32 @SuppressWarnings("serial")
33 public abstract class BeansException extends NestedRuntimeException {
34
35 /**
36 * Create a new BeansException with the specified message.
37 * @param msg the detail message
38 */
39 public BeansException(String msg) {
40 super(msg);
41 }
42
43 /**
44 * Create a new BeansException with the specified message
45 * and root cause.
46 * @param msg the detail message
47 * @param cause the root cause
48 */
49 public BeansException(String msg, Throwable cause) {
50 super(msg, cause);
51 }
52
53
54 @Override
55 public boolean equals(Object other) {
56 if (this == other) {
57 return true;
58 }
59 if (!(other instanceof BeansException)) {
60 return false;
61 }
62 BeansException otherBe = (BeansException) other;
63 return (getMessage().equals(otherBe.getMessage()) &&
64 ObjectUtils.nullSafeEquals(getCause(), otherBe.getCause()));
65 }
66
67 @Override
68 public int hashCode() {
69 return getMessage().hashCode();
70 }
71
72 }