Is there no way (regardless of how "hacky" it is) to detect when Java's System.err
has been written to in order to be able to execute logic if and when this happens? — I'm currently working with a custom subclass of Thread
(let's call it SwallowingThread
) which swallows a number of exceptions in its implementation of Thread.run()
in a manner similar to the following code:
public final class SwallowingThread extends Thread {
...
@Override
public void run() {
ServerSocket socket = new ServerSocket(80, 100);
try {
Socket connected = socket.accept();
// Do stuff with socket here
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
In my code, however, I want to be able to handle cases of UnknownHostException
and IOException
which occur while using an instance of SwallowingThread
; Is there no way to detect that this catching and printing to standard error after it has occured? — I had originally tried writing a UncaughtExceptionHandler
to do this only to find out that it isn't catching the exceptions because they were swallowed rather than simply being e.g. wrapped in a RuntimeException
and thrown onward.
Of course, a "better" way of solving this problem is to re-write the logic for the class, but is there no quick-and-dirty way of solving this issue without having to touch SwallowingThread
?