사실 차이라곤 딱히 없는 것 같다.
단지 try catch는 try와 catch안에서 Promise로 출력되는 것을 막기 위해 async await으로 처리해야한다.
아니 차이가 있다.
then catch는 Promise에 대한 에러처리 및 진행을 다루기 위한 것이고
try catch는 Promise가 아닌 것에 대한 에러처리 및 진행을 다루기 위한 것이다.
// .then.catch
fs.readFile("./text.txt")
.then((data) => console.log(data))
.catch(console.error);
// try catch
const tried = async () => {
try {
const data = await fs.readFile("./text.txt");
console.log(data);
} catch (err) {
console.log(err);
}
};
tried();

둘다 정상적으로 data가 출력된다.
// .then.catch
fs.readFile("./tex.txt")
.then((data) => console.log(data))
.catch(console.error);
// try catch
const tried = async () => {
try {
const data = await fs.readFile("./tex.txt");
console.log(data);
} catch (err) {
console.log(err);
}
};
tried();

둘다 존재하지않은
tex.txt를 readFile 하려하니 오류가 발생한 부분을 각각.catch와catch(err)로 처리하여 같은 출력을 시킨다.
try catch든 .then.catch든 같은 결과를 만들수 있다.
그러기 위해서는 try catch는 async await를 쓰지않으면 Promise 형태로 출력이 되기때문에 async await로 잘 묶어 사용한다.