可能重复:
我如何自己编写例外?
我想在Java中创建一个自定义异常,我该怎么做?
...
try{
...
String word=reader.readLine();
if(word.contains(" "))
/*create custom exception*/
}
catch(){
Run Code Online (Sandbox Code Playgroud)
当我创建自定义异常时throw new...
,我得到错误unreported exception...must be caught or declared to be thrown