St.pop() Error unexpected

import java.util.*;

public class BalanceBrackets{

public static String isBalanced(String s){

     boolean res = false;
    int len = s.length();

    // Stack<Character> st = new Stack<>(); 
     Stack st = new Stack();

    for(int i=0;i<=len;i++){
            char ch = s.charAt(i);

        if(ch =='['|| ch=='{' || ch=='(' ){
           st.push(ch);
        }

        if(ch ==']'|| ch=='}' || ch==')'){
            char c = st.pop();
            res = check(c,ch);
           
            }

        }
        String a = "NO";
        String b = "YES";

        if(!s.isEmpty()){
            return a;
        }else{
            if(res== true)
            return b;
        }
        System.out.println();
        return a;
    }




public static boolean check (char character1,char character2){

     if (character1 == '(' && character2 == ')') 
     return true; 
   else if (character1 == '{' && character2 == '}') 
     return true; 
   else if (character1 == '[' && character2 == ']') 
     return true; 
   else
     return false; 
} 
 public static void main(String[] args) {

    String str = "[{()}]";
    String result = isBalanced(str);
    System.out.println(result);
     
 }
 }

Before making a pop from the stack, you are not checking if the stack is having elements or not. So, in case it is empty it will throw exception

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.