如何引发RuntimeException(&“找不到符号& quot;) [英] How to throw RuntimeException ("cannot find symbol")

查看:63
本文介绍了如何引发RuntimeException(&“找不到符号& quot;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在我的代码中抛出一个异常:

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

throw RuntimeException(msg);

但是当我在NetBeans中构建时,出现此错误:

But when I build in NetBeans I get this error:

C:\....java:50: cannot find symbol
symbol  : method RuntimeException(java.lang.String)
location: class ...
        throw RuntimeException(msg);
1 error

我需要导入什么东西吗?我拼错了吗?我确定我一定在做一些愚蠢的事情:-(

Do I need to import something? Am I misspelling it? I'm sure I must be doing something dumb :-(

推荐答案

抛出新的RuntimeException(msg);

您需要在其中输入 new .它正在创建实例并将其抛出,而不是调用方法.

You need the new in there. It's creating an instance and throwing it, not calling a method.

这篇关于如何引发RuntimeException(&“找不到符号& quot;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆