주석이 달린 "@ExceptionHandler"를 사용하여 SpringMVC3에서 "Error"를 catch하고 싶습니다. throwable 및 모든 예외를 catch 할 수 있지만 "오류"로 시도했을 때 예외가 catch되지 않습니다. 왜 그런가? 아래 코드는 문제를 보여줍니다.명시 적으로 throw 된 경우에도 오류가 잡히지 않는 이유는 무엇입니까?
@Controller
@RequestMapping("/test")
public class TestExceptionController {
static final Logger logger = Logger.getLogger(TestExceptionController.class);
@RequestMapping(method = RequestMethod.GET)
public String processData(int intValue) throws InvalidDataException {
if (intValue < 6) {
try {
throw new Exception();
} catch (Exception e) {
throw new InvalidDataException();
}
}
return "test";
}
@ExceptionHandler(InvalidDataException.class)
public ModelMap handleException(InvalidDataException ex) {
logger.debug("exception catched :" + ex);
return new ModelMap();
}
}
위의 코드는 catch하지만 아래 코드는 catch하지 않습니다. 왜 오류가 잡히지 않는거야?
@Controller
@RequestMapping("/test")
public class TestExceptionController {
static final Logger logger = Logger.getLogger(TestExceptionController.class);
@RequestMapping(method = RequestMethod.GET)
public String processData(int intValue) throws Error{
if (intValue < 6) {
try {
throw new Exception();
} catch (Exception e) {
throw new Error();
}
}
return "test";
}
@ExceptionHandler(Error.class)
public ModelMap handleException(Error ex) {
logger.debug("exception catched :" + ex);
return new ModelMap();
}
}
미래에 새로운 질문을 작성하는 대신 기존 질문을 편집하십시오. 나는 원본을 닫는 것을 투표했다. –
어떤 버전의 Spring3을 사용하고 있습니까? – andyb
이 대답을 했습니까? http://stackoverflow.com/questions/8184593/why-error-is-not-getting-caught-even-when-explicitly-thrown/8212177#8212177 –