My requirement is, I have an application that saves the errors into the database to see later time from the dashboard in my own way. therefore, I want to get the happening errors into string same as the error shows the console. I can the message or other stuff from the error object. but it's not I want. I want to preview the error as the java console shows.
Asked
Active
Viewed 42 times
0
-
2What sort of "error object". Please edit your question to show an example of an error as shown on your Java console. – tgdavies Dec 23 '21 at 12:31
-
1Does this help: https://stackoverflow.com/questions/7242596/e-printstacktrace-in-string – Just another Java programmer Dec 23 '21 at 12:56
1 Answers
0
you can get by using StringWriter
and PrintWriter
like this.
StringWriter sw = new StringWriter();
PrintWriter printWriter = new PrintWriter(sw);
yourException.printStackTrace(printWriter);
String errorLogAsString = sw.toString();

Mafei
- 3,063
- 2
- 15
- 37