1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome;
26
27 import java.io.IOException;
28
29
30
31
32
33
34
35 @SuppressWarnings("serial")
36 public class UTGBException extends Exception {
37 private UTGBErrorCode errorCode = UTGBErrorCode.Unknown;
38
39 public UTGBException(String message) {
40 super(message);
41 }
42
43 public UTGBException(Throwable cause) {
44 super(cause);
45 }
46
47 public UTGBException(String message, Throwable cause) {
48 super(message, cause);
49 }
50
51 public UTGBException(UTGBErrorCode errorCode) {
52 super();
53 this.errorCode = errorCode;
54 }
55
56 public UTGBException(UTGBErrorCode errorCode, Throwable cause) {
57 super(cause);
58 this.errorCode = errorCode;
59 }
60
61 public UTGBException(UTGBErrorCode errorCode, String message, Throwable cause) {
62 super(message, cause);
63 this.errorCode = errorCode;
64 }
65
66 public UTGBException(UTGBErrorCode errorCode, String message) {
67 super(message);
68 this.errorCode = errorCode;
69 }
70
71 public UTGBErrorCode getErrorCode() {
72 return this.errorCode;
73 }
74
75 @Override
76 public String getMessage() {
77 return "[" + errorCode.name() + "] " + super.getMessage();
78 }
79
80 public static UTGBException convert(Exception e) {
81 if (UTGBException.class.isInstance(e)) {
82 UTGBException xe = UTGBException.class.cast(e);
83 return xe;
84 }
85 else if (IOException.class.isInstance(e)) {
86 return new UTGBException(UTGBErrorCode.IO_ERROR, e);
87 }
88 else {
89 return new UTGBException(UTGBErrorCode.INHERITED, e);
90 }
91 }
92
93 }