拉莫斯之舞
您应该能够创建一个扩展Exception该类的自定义异常类,例如:class WordContainsException extends Exception{ // Parameterless Constructor public WordContainsException() {} // Constructor that accepts a message public WordContainsException(String message) { super(message); } }用法:try{ if(word.contains(" ")) { throw new WordContainsException(); }}catch(WordContainsException ex){ // Process message however you would like}