Your code is in a static block. If in a very rare case of JVM implementation (if any), the static block is not where you should handle any errors or exceptions, if possible. This is due to the fact that you do not have much control over the execution of the static block (if you do not have a dynamic class loader), which is quite rare.
So, if this is true, move your code to the instance block, and it should work fine.
So, when something unexpected happens in your static block, your application is not expected to continue. Thus, all of these unexpected exceptions in a static block will be thrown by ExceptionInIntiializerError. You can refer to here
source share