如何在catch里输出try里的变量

public boolean call(String message){
    try{
        def result = JSON.parse(message)
        def data = result.body
        if(data.id){
            ....
         }
          return true
     }catch(Exception e){
         Log.getInstance().error((String)Message.get("G-002"),e)
      }
      return false
}

我想发生异常时、在catch的异常信息里输出data.id的值,得怎么改才行?

变量定义放在try上面,放在try中定义,他只在try代码块中有用,代码修改如下,有帮助的话采纳一下哦!

public boolean call(String message){
    def result = JSON.parse(message)
    def data = result.body
    int s = data.id
    tryif(s){
            ....
         }
          return true
     }catch(Exception e){
         Log.getInstance().error((String)Message.get("G-002"),e)
      }
      return false
}

data申明在 try上边,然后就可以使用

 public static void main(String[] args) {
        int a[]=new int[1];
        int i=0;
        try {
            for(  i = 1; i<=10; i++) {
                a[i]=1;
            }
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("报错的值为"+i);//输出为9
        }
        }