I have a plugin module that goes into a web application.
If the module does not load correctly, it does not make sense for the web application to go on, and the web application should probably not load at all, we would prefer this module to initialize correctly always.
If I were to throw a runtime exception, it would get into the logs, and just get ignored since the application will continue anyway, and the end users would never know…
I know that errors are meant to be thrown only under exceptional conditions, and they generally have to do with situations that the system cannot recover from, but what would you do in such a situation?
I have a plugin module that goes into a web application. If the module
Share
The only
Errorwhich I’ve regularly used in business code isExceptionInInitializerError. You have no other choice instaticinitializer blocks.But even if you throw that inside a webapplication, the webapplication would still continue listening on HTTP requests. Your best bet is to do the module loading or initialization inside a
Filterlistening on anurl-patternof/*and let theFilterblock the HTTP requests accordingly. E.g.This would yield a HTTP 500 error with the given message.