2.0.0
Changes
Won't exit by default in Node
- Error won't exit the program by default, instead, it will throw an error
In v1.x
, when you try to unwrap
a Result
that is an error, the program will exit by default in Node. In most cases or a strong system, you may want to handle the error by yourself.
In v2
, you can set a customized panic
function by using the function setPanic
. When an error occurs, it will call your customized panic function, then you can handle it somewhere.
class MyError extends Error {}
setPanic((msg: string) => {
throw new MyError(msg)
})
However, you can still exit the program by specifying the option panic: true
.
err('some error').unwrap({panic: true})
NOTE that you should implement the exit behavior by yourself if you are using customized panic function.