. Net to Java.03. check exception and non-query exception,. net to java.03
After turning to Java, I found a very demon thing. Why is there a throws XXXXException behind some methods?
For example, the following code
@Override public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(requestEntity, responseType); ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType); return execute(url, method, requestCallback, responseExtractor, uriVariables); }
This is a syntax not available in. NET. An exception occurs during query.
This is an explanation taken from Java core technology. I feel very clear.
The Java language specification calls all exceptions derived from the Error class and RuntimeException class as unchecked exceptions [in the green section], and all other exceptions are called checked) exception [blue part in ].
The compiler checks whether an exception processor is provided for all checked exceptions.
The check exception can be either handled internally by the method, or the caller is prompted for handling through the method declaration (for example, the file cannot be found)
Non-checked exceptions are either uncontrollable (such as OOM) or avoided. In theory, they can also be completely avoided (such as the case of null reference)