Initialization in java in try {} catch () {}, compilation error

In

Java development, a global variable is declared in the class and is not initialized, then the variable is initialized in try {}, and the member variable is called outside the try {} block. The error variable is not initialized, but the variable has indeed been assigned, so why report an error?

Mar.05,2021

String s;
        try {
            s="hello world";
        } catch (Exception e) {
            s="123";//
            e.printStackTrace();
        }
      System.out.println(s);//catchtrys
Menu