How to throw RuntimeException (“cannot find symbol”)

后端 未结 9 1098
别跟我提以往
别跟我提以往 2021-02-03 18:47

I\'m trying to throw an exception in my code like this:

throw RuntimeException(msg);

But when I build in NetBeans I get this error:

<         


        
9条回答
  •  温柔的废话
    2021-02-03 19:26

    using new keyword we always create a instance (new object) and throwing it , not called a method

    throw new RuntimeException("Your Message");
    
    You need the new in there. It's creating an instance and throwing it, not calling a method.
    
    int no= new Scanner().nextInt();   // we crate an instance using new keyword and throwing it 
    

    using new keyword memory clean [because use and throw]

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
    
            //do your work here..
        }
    }, 1000);
    

提交回复
热议问题