Merge branch 'next' into dev/image
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneException.java
1 /*
2  * Sone - SoneException.java - Copyright © 2010 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.core;
19
20 /**
21  * A Sone exception.
22  *
23  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
24  */
25 public class SoneException extends Exception {
26
27         /**
28          * Defines the different error. This is an enum instead of custom exceptions
29          * to keep the number of exceptions down. Specialized exceptions might still
30          * exist, though.
31          */
32         public static enum Type {
33
34                 /** An invalid Sone name was specified. */
35                 INVALID_SONE_NAME,
36
37                 /** An invalid URI was specified. */
38                 INVALID_URI,
39
40                 /** An insert failed. */
41                 INSERT_FAILED,
42
43         }
44
45         /** The type of the exception. */
46         private final Type type;
47
48         /**
49          * Creates a new Sone exception.
50          *
51          * @param type
52          *            The type of the occured error
53          */
54         public SoneException(Type type) {
55                 this.type = type;
56         }
57
58         /**
59          * Creates a new Sone exception.
60          *
61          * @param type
62          *            The type of the occured error
63          * @param message
64          *            The message of the exception
65          */
66         public SoneException(Type type, String message) {
67                 super(message);
68                 this.type = type;
69         }
70
71         /**
72          * Creates a new Sone exception.
73          *
74          * @param type
75          *            The type of the occured error
76          * @param cause
77          *            The cause of the exception
78          */
79         public SoneException(Type type, Throwable cause) {
80                 super(cause);
81                 this.type = type;
82         }
83
84         /**
85          * Creates a new Sone exception.
86          *
87          * @param type
88          *            The type of the occured error
89          * @param message
90          *            The message of the exception
91          * @param cause
92          *            The cause of the exception
93          */
94         public SoneException(Type type, String message, Throwable cause) {
95                 super(message, cause);
96                 this.type = type;
97         }
98
99         //
100         // ACCESSORS
101         //
102
103         /**
104          * Returns the type of this exception.
105          *
106          * @return The type of this exception (may be {@code null})
107          */
108         public Type getType() {
109                 return type;
110         }
111
112 }