I have a try-catch
block; inside try
, I read variable N
from console and initialize an Array[N]
. I need to use Array
later. If I use it outside try
block, I get an error
java variable may not have been initialized
.
I understand it, but what should I do, write the whole program inside try
block, really? Readability of such program is worse and I use try
on the code where is no exceptions
are possible. Is there a workaround? I tried a boolean
variable which checks was there an exception and use it later in a if
statement - no results.