How to throw RuntimeException (“cannot find symbol”)

后端 未结 9 1091
别跟我提以往
别跟我提以往 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-03 19:35

    You need to create the instance of the RuntimeException, using new the same way you would to create an instance of most other classes:

    throw new RuntimeException(msg);
    

提交回复
热议问题