我发现很少有例外IllegalArgumentException
,throws Exception
不需要添加throws Exception
来抛出异常。为什么以及哪些类似的异常不需要添加public class WithoutThrowsException {
public static void printSomething(String str) {
if(str == null) throw new NullPointerException("Inputted string is null ");
if(str.equals("rocket")) throw new IllegalArgumentException("Illegal argument exception ");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World!!");
printSomething("rocket");
System.out.println("Mission accomplished !");
}
}
?
@GetMapping(value="/cui",produces = MediaType.APPLICATION_XML_VALUE)
public String cui() {
String responseXML = // This is my final result object which is XML.
return responseXML;
}