Finally or just the code?
: 5
2
-
1
try..catchfinally:try { work work } catch (e) { handle errors } finally { } -
2
try..catch:try { work work } catch (e) { handle errors }
finally
try..catch
try..catch return finally try..catch return
function f() {
try {
alert('start');
return "result";
} catch (e) {
/// ...
} finally {
alert('cleanup!');
}
}
f(); // cleanup!
throw :
function f() {
try {
alert('start');
throw new Error("an error");
} catch (e) {
// ...
if("can't handle the error") {
throw e;
}
} finally {
alert('cleanup!')
}
}
f(); // cleanup!
finally f