If an exception is thrown from within a servlet’s
init() method, I would expect Tomcat to act on it by not allowing the context to load. This makes sense to me.
But I have recently discovered that Tomcat allows exceptions to be thrown from within the initialisation phase of a servlet‘s life-cycle without side-affects, while exceptions thrown from within the initialisation phase of a filter‘s life-cycle causes a Catalina
SEVERE error resulting in the context not loading.
Hmmm…. Not sure why this is the case, but until someone can explain it to me I will treat it as a bug within Tomcat. We are using v5.5.25.
FYI, I came across this while trying to implement an application configuration servlet which loads on start-up setting various application properties based on environment variables et al. Due to the described ‘bug’, I have ended up using a filter for the job instead of a servlet as it behaves as I would expect. A better solution would be to use Spring, I know, but we are still having to maintain some complex legacy apps which are not worth spending the time converting to Spring.