Start Event Loop

Created by CecilWesterhof.

I often want an event loop that runs forever and terminates when there is an error. For this I created:

# To start an eventloop, default it also makes a bgerror fatal.
# Normally I start an event loop always 'forever',
# this combined with that default a bgerror is fatal makes it for me a handy proc.
proc startEventLoop {{bgerrorIsFatal True}} {
    if {${bgerrorIsFatal}} {
        interp bgerror {} fatal
    }
    vwait forever
}

And it uses:

proc fatal {msg info} {
    set error [dict get ${info} -code]
    if {[expr {[string is integer ${error}]}]} {
        set errorCode ${error}
    } else {
        puts stderr "${error} is not an interger"
        set errorCode 255
    }
    puts stderr [dict get ${info} -errorinfo]
    exit ${errorCode}
}

As always: comments, tips and questions are appreciated.