Add TrapPanic

This commit is contained in:
rwxrob 2022-04-06 12:39:55 -04:00
parent 3aea8cbeca
commit 6b76c5919f
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

View File

@ -302,9 +302,10 @@ func ArgsOrIn(args []string) string {
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.
// panic by logging it before exiting with a return value of 1.
var TrapPanic = func() {
if r := recover(); r != nil {
ExitError(r)
log.Println(r)
os.Exit(1)
}
}