This is the code that I\'ve written.
int num;
try {
num=100;
DoSomething();
System.out.println(num);
} catch(Exception e) {
DoSomething1();
}
Exception handling can confuse the compiler. In this case, you know that an exception cannot possibly be thrown BEFORE the variable num
is set, but the compiler doesn't know this.
The compiler thinks that an exception might be thrown before num
has been set in which case num
would not have been initialized when you try to print it outside the try-catch block.