Handling Errors with try-catch-finally
What resource management pattern is demonstrated?
class Timer {
constructor() {
this.timerId = null;
}
start() {
try {
this.timerId = setTimeout(() => {}, 1000);
} catch (error) {
// Handle error
} finally {
// Clear in case of error
if (this.timerId) {
clearTimeout(this.timerId);
}
}
}
}