try/catch กับ async
ห่อจุดที่อาจล้ม
async function start() {
const status = document.querySelector("#status");
status.textContent = "กำลังโหลด...";
try {
const notes = await loadNotes();
status.textContent = "โหลดแล้ว " + notes.length + " รายการ";
// render รายการ...
} catch (err) {
console.error(err);
status.textContent = "โหลดไม่สำเร็จ ลองใหม่ภายหลัง";
}
}
ผลลัพธ์ที่คาดหวัง
ผู้เห็นข้อความสถานะชัดเจนทั้งตอนสำเร็จและล้มเหลว · error รายละเอียดอยู่ใน console สำหรับดีบัก