Handling Errors with try-catch-finally
What error handling best practice is shown here?
function fetchData() {
return fetch('/api/data')
.catch(error => {
throw new NetworkError('Failed to fetch data', { cause: error });
});
}
try {
await fetchData();
} catch (error) {
if (error instanceof NetworkError) {
// Handle network error
}
}