I want to hide an exception from logging it’s stacktrace in log4j.
My application throws a runtime exception out and I just want the message of the exception and not the stacktrace for it to log.
I am wondering what the log4j property should be for this.
Thanks
Steven
If it is a standalone java app then you could use Thread.UncaughtExceptionHandler
If it is a web application then using default error page would solve your issue (didn’t verify). You might also want to check if you can use Thread.UncaughtExceptionHandler in web applications. But if the Web Container already uses this for some purpose, then setting it (replacing it) by yourself might affect the functionality of the Web Container. To be safe, it’s better to delegate to the existing handler (if any) from your handler in such a scenario (use the relevant getter method).
Also, if a SecurityManager is enforced, you need to have the permission to invoke this method. Otherwise it might result in SecurityException being thrown.