- public static void main(String[] args) throws Exception {
- try {
- try {
- try {
- testDeeper();
- } catch (Exception e) {
- throw new Exception("Less deep exception", e);
- }
- } catch (Exception e) {
- throw new RuntimeException("Top exception", e);
- }
- } catch (Exception e) {
- CmsExceptionsChain vjeSystemErrors = new CmsExceptionsChain(e);
- ObjectMapper objectMapper = new ObjectMapper();
- System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(vjeSystemErrors));
- e.printStackTrace();
+ /** recursive */
+ protected void writeException(Throwable exception) {
+ SystemException systemException = new SystemException(exception);
+ exceptions.add(systemException);
+ Throwable cause = exception.getCause();
+ if (cause != null)
+ writeException(cause);
+ }
+
+ public List<SystemException> getExceptions() {
+ return exceptions;
+ }
+
+ public void setExceptions(List<SystemException> exceptions) {
+ this.exceptions = exceptions;
+ }
+
+ /** An exception in the chain. */
+ public static class SystemException {
+ private String type;
+ private String message;
+ private List<String> stackTrace;
+
+ public SystemException() {
+ }
+
+ public SystemException(Throwable exception) {
+ this.type = exception.getClass().getName();
+ this.message = exception.getMessage();
+ this.stackTrace = new ArrayList<>();
+ StackTraceElement[] elems = exception.getStackTrace();
+ for (int i = 0; i < elems.length; i++)
+ stackTrace.add("at " + elems[i].toString());