Why doesn't Java allow to throw a checked exception from static initialization block? -


why doesn't java allow throw checked exception static initialization block? reason behind design decision?

because not possible handle these checked exceptions in source. not have control on initialization process , static{} blocks cannot called source surround them try-catch.

because cannot handle error indicated checked exception, decided disallow throwing of checked exceptions static blocks.

the static block must not throw checked exceptions still allows unchecked/runtime-exceptions thrown. according above reasons unable handle these either.

to summarize, restriction prevents (or @ least makes harder for) developer building can result in errors application unable recover.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -