Add TrapPanic

This commit is contained in:
rwxrob 2022-04-06 12:36:27 -04:00
parent 5084c30d94
commit 3aea8cbeca
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

View File

@ -300,3 +300,11 @@ func ArgsOrIn(args []string) string {
// strings.Fields) to ensure that hard-coded arguments containing
// whitespace are properly handled.
var Aliases = make(map[string][]string)
// TrapPanic recovers from any panic and more gracefully displays the
// error as an exit message. Simply add defer TrapPanic() when wanted.
var TrapPanic = func() {
if r := recover(); r != nil {
ExitError(r)
}
}