why does the catch block give an error with variable not initialized in Java

后端 未结 7 977
臣服心动
臣服心动 2021-01-12 00:42

This is the code that I\'ve written.

int num;
try {
    num=100;
    DoSomething();
    System.out.println(num);
} catch(Exception e) {
    DoSomething1();
}         


        
相关标签:
7条回答
  • 2021-01-12 01:17

    The problem is that num is not initializated, int num = -1; And the error will go away ;)

    0 讨论(0)
提交回复
热议问题