1 /*
2 * Copyright (c) 2008, The JUNG Authors
3 *
4 * All rights reserved.
5 *
6 * This software is open-source under the BSD license; see either
7 * "license.txt" or
8 * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
9 */
10
11 package edu.uci.ics.jung.io.graphml;
12
13 import edu.uci.ics.jung.io.GraphIOException;
14
15 import javax.xml.stream.XMLStreamException;
16
17 /**
18 * Converts an exception to the a GraphIOException. Runtime exceptions
19 * are checked for the cause. If the cause is an XMLStreamException, it is
20 * converted to a GraphIOException. Otherwise, the RuntimeException is
21 * rethrown.
22 *
23 * @author Nathan Mittler - nathan.mittler@gmail.com
24 */
25 public class ExceptionConverter {
26
27 /**
28 * Converts an exception to the a GraphIOException. Runtime exceptions
29 * are checked for the cause. If the cause is an XMLStreamException, it is
30 * converted to a GraphReaderException. Otherwise, the RuntimeException is
31 * rethrown.
32 *
33 * @param e the exception to be converted
34 * @throws GraphIOException the converted exception
35 */
36 static public void convert(Exception e) throws GraphIOException {
37
38 if (e instanceof GraphIOException) {
39 throw (GraphIOException) e;
40 }
41
42 if (e instanceof RuntimeException) {
43
44 // If the cause was an XMLStreamException, throw a GraphReaderException
45 if (e.getCause() instanceof XMLStreamException) {
46 throw new GraphIOException(e.getCause());
47 }
48
49 throw (RuntimeException) e;
50 }
51
52 throw new GraphIOException(e);
53 }
54 }