1 package org
.argeo
.cms
.util
;
3 import java
.util
.ArrayList
;
7 * Serialisable wrapper of a {@link Throwable}. typically to be written as XML
8 * or JSON in a server error response.
10 public class ExceptionsChain
{
11 private List
<SystemException
> exceptions
= new ArrayList
<>();
13 public ExceptionsChain() {
16 public ExceptionsChain(Throwable exception
) {
17 writeException(exception
);
21 protected void writeException(Throwable exception
) {
22 SystemException systemException
= new SystemException(exception
);
23 exceptions
.add(systemException
);
24 Throwable cause
= exception
.getCause();
26 writeException(cause
);
29 public List
<SystemException
> getExceptions() {
33 public void setExceptions(List
<SystemException
> exceptions
) {
34 this.exceptions
= exceptions
;
37 /** An exception in the chain. */
38 public static class SystemException
{
40 private String message
;
41 private List
<String
> stackTrace
;
43 public SystemException() {
46 public SystemException(Throwable exception
) {
47 this.type
= exception
.getClass().getName();
48 this.message
= exception
.getMessage();
49 this.stackTrace
= new ArrayList
<>();
50 StackTraceElement
[] elems
= exception
.getStackTrace();
51 for (int i
= 0; i
< elems
.length
; i
++)
52 stackTrace
.add("at " + elems
[i
].toString());
55 public String
getType() {
59 public void setType(String type
) {
63 public String
getMessage() {
67 public void setMessage(String message
) {
68 this.message
= message
;
71 public List
<String
> getStackTrace() {
75 public void setStackTrace(List
<String
> stackTrace
) {
76 this.stackTrace
= stackTrace
;
80 public String
toString() {
81 return "System exception: " + type
+ ", " + message
+ ", " + stackTrace
;
87 public String
toString() {
88 return exceptions
.toString();