
catch (Exception e) {
logger.error(messageSource.getMessage("error.get.codelist.reason",
new String[] {}, Locale.getDefault()), e);
throw new EmpException(messageSource, "error.get.codelist", e);
}
public EmpException(MessageSource messageSource, String messageKey,
Object[] messageParameters, Throwable wrappedException) {
super(messageSource, messageKey, messageParameters, wrappedException);
}
public class CodeServiceImpl implements CodeService, ApplicationContextAware {
private Log logger = LogFactory.getLog(CodeServiceImpl.class);
private MessageSource messageSource = null;
// 중략
public ArrayList getCodeList(String codeType) throws EmpException {
try {
return codeDAO.getCodeList(codeType);
}
catch (Exception e) {
logger.error(messageSource.getMessage("error.get.codelist.reason",
new String[] {}, Locale.getDefault()), e);
throw new EmpException(messageSource, "error.get.codelist", e);
}
}
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
messageSource = (MessageSource) applicationContext
.getBean("messageSource");
}
}
error.get.codelist=Fail to get code list. error.get.codelist.solution=Fail to get code list. Please check if DB is started. error.get.codelist.reason=Fail to get code list. DB may be shutdowned.
public ArrayList getCodeList(String codeType) throws Exception {
return (ArrayList) queryService.find("getCodeList",
new Object[] { codeType });
}
JVM(자바 가상 머신)에서 Exception처리를 위해 동작하는 방식을 살펴보면, JVM은 method호출의 역순으로 현재 thread에서 호출된 method를 대표하는 stack 프레임을 stack에 담고 있다가 Exception가 발생하면 Exception에 대한 첫 번째 처리(try catch)를 한 method를 stack에서 찾아낸다. 이러한 작업은 JVM의 많은 리소스가 소요된다.
그러므로 Exception은 반드시 Exception발생이 의미있는 작업일 경우에만 발생해야 한다. 만일 이러한 상황이 의미 있는 형태로 프로그램적으로 처리될 수 있으면 Exception 발생을 피해야 한다. System Exception의 예는 ConfigurationException (시작 시에 Data Load를 실패한 경우) 같은 것이 대상이 될 수 있다. 이러한 Exception는 문제를 수정하고 재 구동하는 것 이외에는 사용자가 처리할 수 있는 것이 없다. 이러한 예가 시스템 Exception 이며, RuntimeException으로 처리될 수 있다. SQLException같은 경우는 상황에 따라 시스템 오류 혹은 어플리케이션 문제를 지칭한다. 각 경우에 일반적으로 SQLException은 어플리케이션 로직에서 던지지 않는 checked exception으로 모델링한다.