1 package org
.argeo
.util
;
3 import java
.util
.ArrayList
;
6 /** Serialisable wrapper of a {@link Throwable}. */
7 public class ExceptionsChain
{
8 private List
<SystemException
> exceptions
= new ArrayList
<>();
10 public ExceptionsChain() {
13 public ExceptionsChain(Throwable exception
) {
14 writeException(exception
);
18 protected void writeException(Throwable exception
) {
19 SystemException systemException
= new SystemException(exception
);
20 exceptions
.add(systemException
);
21 Throwable cause
= exception
.getCause();
23 writeException(cause
);
26 public List
<SystemException
> getExceptions() {
30 public void setExceptions(List
<SystemException
> exceptions
) {
31 this.exceptions
= exceptions
;
34 /** An exception in the chain. */
35 public static class SystemException
{
37 private String message
;
38 private List
<String
> stackTrace
;
40 public SystemException() {
43 public SystemException(Throwable exception
) {
44 this.type
= exception
.getClass().getName();
45 this.message
= exception
.getMessage();
46 this.stackTrace
= new ArrayList
<>();
47 StackTraceElement
[] elems
= exception
.getStackTrace();
48 for (int i
= 0; i
< elems
.length
; i
++)
49 stackTrace
.add("at " + elems
[i
].toString());
52 public String
getType() {
56 public void setType(String type
) {
60 public String
getMessage() {
64 public void setMessage(String message
) {
65 this.message
= message
;
68 public List
<String
> getStackTrace() {
72 public void setStackTrace(List
<String
> stackTrace
) {
73 this.stackTrace
= stackTrace
;
77 public String
toString() {
78 return "System exception: " + type
+ ", " + message
+ ", " + stackTrace
;
84 public String
toString() {
85 return exceptions
.toString();