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
当前内容版权归 miguelmota 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 miguelmota .