Very similar to Python's "finally" keyword [0] used in a try block, the "Exit Traps" are meant to allow for clean-up action(s) if a script fails.
[0]: https://docs.python.org/3/tutorial/errors.html#defining-clea...
[0]: https://docs.python.org/3/tutorial/errors.html#defining-clea...
try{
#code that can throw errors
} catch {
#handle error
} finally {
#code
}
And try{
#throw err
}catch {
#handle
}
#code...
Surely in pretty much all languages the two are equivalent, so what is finally's purpose as a token?The trick in this post is different because for one bash doesn't have finally, and even if it did you couldn't use it to catch all of a script's errors.
Here's a "fun" example in Javascript:
function foo() {
try {
return 42
} finally {
return "boo!"
}
}