attempt-statement
v1.1.0
Published
An attempt statement for js
Downloads
163
Readme
attempt-statement
const attempt = require('attempt-statement')
attempt(() => {
consoe.log('I misspelled console')
}).rescue((error) => {
console.log('Error: ' + error)
}).else(() => {
console.log('No error yay')
}).ensure(() => {
console.log('This will always be run')
}).end()
// Output:
// Error: ReferenceError: consoe is not defined
// This will always be run
equivalent to:
let error = false
try {
consoe.log('I misspelled console')
} catch(error) {
console.log('Error: ' + error)
error = true
}
if (error === false) {
console.log('No error yay')
}
console.log('This will always be run')
there is no built in way in javascript to achieve the else behavior so attempt-statement is the way to go.