2017-09-23 3 views
1

여러 catch를 사용할 수 없습니까? RestClientException에 대한 최초의 캐치 사용 및 초 사용 HttpStatusCodeExceptionError : (229, 12) java : 예외 org.springframework.web.client.HttpStatusCodeException이 이미 catch되었습니다.

try { 
     ResponseEntity<Stdo> responseEntity = restTemplate.exchange(theUrl, HttpMethod.POST, entity, Stdo.class); 
    }catch (RestClientException ex) { 
      if (ex.toString().contains("Connection timed out")) { 
      } 
    }catch(HttpStatusCodeException ex) 
    { 
     // get http status code 
    } 
} 

오류는 문서에서

Error:(229, 12) java: exception org.springframework.web.client.HttpStatusCodeException has already been caught 

답변

1

계층 구조는 읽고 오류를 정당화. HttpStatusCodeException

extends RestClientResponseException 

RestClientResponseException

extends RestClientException 

따라서 오류. 복수의 catch을 역순으로 사용할 수 있습니다.

catch(HttpStatusCodeException ex) { 
    // get http status code 
} catch (RestClientException ex) { 
    if (ex.toString().contains("Connection timed out")) {...} 
}