1 /*
2 * Oceanus: Java Utilities
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.oceanus.base;
18
19 import java.io.Serial;
20
21 /**
22 * Exception extension class. Provides capability of attaching ExceptionClass and Causing object to
23 * exception.
24 *
25 * @author Tony Washer
26 */
27 public abstract class OceanusException
28 extends Exception {
29 /**
30 * Required serialisation field.
31 */
32 @Serial
33 private static final long serialVersionUID = 3100519617218144798L;
34
35 /**
36 * The associated object.
37 */
38 private final transient Object theObject;
39
40 /**
41 * Create a wrapped Exception object based on an underlying exception.
42 *
43 * @param c the underlying exception
44 */
45 protected OceanusException(final Throwable c) {
46 super(c);
47 theObject = null;
48 }
49
50 /**
51 * Create a new Exception object based on a string and class.
52 *
53 * @param s the description of the exception
54 */
55 protected OceanusException(final String s) {
56 super(s);
57 theObject = null;
58 fillInStackTrace();
59 }
60
61 /**
62 * Create a new Exception object based on a string and an underlying exception.
63 *
64 * @param s the description of the exception
65 * @param c the underlying exception
66 */
67 protected OceanusException(final String s,
68 final Throwable c) {
69 super(s, c);
70 theObject = null;
71 }
72
73 /**
74 * Create a new Exception object based on a string and an object.
75 *
76 * @param o the associated object
77 * @param s the description of the exception
78 */
79 protected OceanusException(final Object o,
80 final String s) {
81 super(s);
82 theObject = o;
83 fillInStackTrace();
84 }
85
86 /**
87 * Create a new Exception object based on a string, an object and an underlying exception.
88 *
89 * @param o the associated object
90 * @param s the description of the exception
91 * @param c the underlying exception
92 */
93 protected OceanusException(final Object o,
94 final String s,
95 final Throwable c) {
96 super(s, c);
97 theObject = o;
98 }
99
100 /**
101 * Get the associated object.
102 *
103 * @return the associated object
104 */
105 public Object getObject() {
106 return theObject;
107 }
108 }