exceptions
exceptions
Node.js
function foo() {
throw Error('my exception')
}
function main() {
foo()
}
process.on('uncaughtException', err => {
console.log(`caught exception: ${err.message}`)
process.exit(1)
})
main()
Output
caught exception: my exception
Go
package main
import (
"fmt"
)
func foo() {
panic("my exception")
}
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Printf("caught exception: %s", r)
}
}()
foo()
}
Output
caught exception: my exception
