source: osm/applications/editors/josm/plugins/opendata/includes/org/jopendocument/util/ExceptionUtils.java

Last change on this file was 28000, checked in by donvip, 14 years ago

Import new "opendata" JOSM plugin

File size: 1.7 KB
Line 
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2008 jOpenDocument, by ILM Informatique. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of the GNU
7 * General Public License Version 3 only ("GPL").
8 * You may not use this file except in compliance with the License.
9 * You can obtain a copy of the License at http://www.gnu.org/licenses/gpl-3.0.html
10 * See the License for the specific language governing permissions and limitations under the License.
11 *
12 * When distributing the software, include this License Header Notice in each file.
13 *
14 */
15
16package org.jopendocument.util;
17
18import java.lang.reflect.Constructor;
19
20/**
21 * Utilitaires pour les exceptions.
22 *
23 * @author Sylvain CUAZ 25 nov. 2004
24 */
25public class ExceptionUtils {
26 /** Static only. */
27 private ExceptionUtils() {
28 super();
29 }
30
31 /**
32 * Crée une exception avec message et cause.
33 *
34 * @param <T> le type d'exception à créer.
35 * @param exnClass la classe de l'exception à créer, eg IOException.class.
36 * @param msg le message.
37 * @param cause la cause.
38 * @return une exception initialisée.
39 */
40 static public <T extends Exception> T createExn(Class<T> exnClass, String msg, Throwable cause) {
41 T instance = null;
42 try {
43 Constructor<T> ctor = exnClass.getConstructor(new Class[] { String.class });
44 instance = ctor.newInstance(new Object[] { msg });
45 } catch (Exception exn) {
46 throw new IllegalArgumentException(exnClass + " has no working String constructor");
47 }
48 instance.initCause(cause);
49 return instance;
50 }
51}
Note: See TracBrowser for help on using the repository browser.