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
Post a Comment