1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.common.utils;
\r
14 import java.lang.reflect.Constructor;
\r
15 import java.lang.reflect.InvocationTargetException;
\r
18 * Utilities for exception propagation in the database client implementation.
\r
20 * @author Tuukka Lehtonen
\r
22 public final class ExceptionUtil {
\r
25 * Re-wrap and rethrow a previously caught exception.
\r
28 * Attempts to create a new instance of the specified throwable itself with
\r
29 * the specified Throwable as its cause.
\r
31 * Should the construction of the new throwable fail, the method will log
\r
32 * the error with {@link Logger} and just throw the originally
\r
33 * specified throwable itself.
\r
35 * @param <T> the concrete class of the throwable to be wrapped
\r
36 * @param t the throwable to wrap
\r
37 * @return never returns
\r
38 * @throws T the new wrapping throwable or the original throwable if the
\r
41 public static <T extends Throwable> void wrapAndThrow(T t) throws T {
\r
43 @SuppressWarnings("unchecked")
\r
44 Class<T> clazz = (Class<T>) t.getClass();
\r
45 Constructor<T> ctor = clazz.getConstructor(Throwable.class);
\r
46 T parent = ctor.newInstance(t);
\r
48 } catch (InstantiationException e1) {
\r
49 Logger.defaultLogError(e1);
\r
51 } catch (IllegalAccessException e1) {
\r
52 Logger.defaultLogError(e1);
\r
54 } catch (IllegalArgumentException e1) {
\r
55 Logger.defaultLogError(e1);
\r
57 } catch (InvocationTargetException e1) {
\r
58 Logger.defaultLogError(e1);
\r
60 } catch (SecurityException e1) {
\r
61 Logger.defaultLogError(e1);
\r
63 } catch (NoSuchMethodException e1) {
\r
64 Logger.defaultLogError(e1);
\r