Get detail messages of chained exceptions Java

后端 未结 5 580
面向向阳花
面向向阳花 2020-12-28 16:29

I\'d like to know how I could I thorw a \"final\" Exception, containing a detail message with all the detail messages of a number of chained exceptions.

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 16:50

    I had saved all attributes in a class object with the following example:

    public List getMessageList(Throwable throwable) {
            List errorMessageList =  new ArrayList();
            while (throwable != null) {
                ErrorMessage message = new ErrorMessage();
                message.set_message( throwable.getMessage());
                message.set_line(throwable.getStackTrace()[0].getLineNumber());
                message.set_methodName(throwable.getStackTrace()[0].getMethodName());
                message.set_fileName(throwable.getStackTrace()[0].getFileName() );
                message.set_className(throwable.getStackTrace()[0].getClassName());
                errorMessageList.add(message);
                throwable = throwable.getCause();
            }
            return errorMessageList; 
        }
    

提交回复
热议问题