try...catch...finally and throw
예외 처리
try {
// 실행될 선언들
} catch (err) {
// try 블록에서 예외가 발생했을 때 실행될 선언들
} finally {
// try 선언이 완료된 이후에 실행된 선언들. 이 선언들은 예외 발생 여부와 상관없이 실행된다.
}async & await + 예외 처리
export default Vue.extend({
...
methods: {
async onClickCreate() {
this.isLoading = true;
const data = {
title: this.title,
...
};
try {
if (!this.title) {
throw Error("필수 항목입니다.");
}
const response = await api.post('..api url..', data);
if (response.status === 200) {
console.log("Success");
} else {
console.log(response.status);
CommonUIControl.ShowErrorToast(response.status);
}
} catch (error) {
console.log(error);
} finally {
console.log('finally');
}
},
}
...
});참고
✍️ 끄적끄적
Last updated