01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.core.util;
16:
17: import org.apache.commons.lang.exception.NestableRuntimeException;
18: import org.araneaframework.core.Assert;
19:
20: /**
21: * This utility class contains methods for managing exceptions.
22: *
23: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
24: */
25: public abstract class ExceptionUtil {
26:
27: /**
28: * Unchecks the exception by rethrowing
29: * unchecked exceptions and wrapping checked exceptions inside
30: * <code>NestableRuntimeException</code>.
31: *
32: * @param e exception
33: *
34: * @return nothing really, just rethrows suitable <code>RuntimeException</code>
35: */
36: public static RuntimeException uncheckException(Exception e) {
37: Assert.notNullParam(e, "e");
38:
39: if (e instanceof RuntimeException)
40: throw (RuntimeException) e;
41:
42: throw new NestableRuntimeException(e);
43: }
44:
45: /**
46: * Unchecks the exception by rethrowing
47: * unchecked exceptions and wrapping checked exceptions inside
48: * <code>NestableRuntimeException</code>.
49: * @param message
50: * @param e exception
51: *
52: * @return nothing really, just rethrows suitable <code>RuntimeException</code>
53: *
54: * @since 1.0.11
55: */
56: public static RuntimeException uncheckException(String message,
57: Exception e) {
58: Assert.notNullParam(e, "e");
59: throw new NestableRuntimeException(message, e);
60: }
61: }
|