I need to store an error message in a string after the error has occurred. I am unable to use the try and catch blocks as the error will appear after the initial code is run.
Before I was using the code below to store the error message in a file when it appeared:
PrintStream printS = new PrintStream("file.txt");
System.setErr(pst);
However I want to store it and a string and send this string else where after the error occured. I have tried already using a byte array output stream:
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
PrintStream printS = new PrintStream(byteArray);
System.setErr(pst);
String tester = byteArray.toString(StandardCharsets.UTF_8);
But when I try to print the string it is empty and does not contain the error. Does anyone know how I can run code after a error has occurred, so I can send this error message elsewhere?