1
0
Fork 0

add printerror() function that prints error vectors as set by call()

This commit is contained in:
mfranz 2007-06-16 08:21:39 +00:00
parent 6a7dc46bd2
commit 59c303bcc1

View file

@ -33,6 +33,9 @@
# prints execution time in seconds,
# prefixed with <label>.
#
# debug.printerror(<err-vector>) ... prints error vector as set by call()
#
#
# CAVE: this file makes extensive use of ANSI color codes. These are
# interpreted by UNIX shells and MS Windows with ANSI.SYS extension
# installed. If the color codes aren't interpreted correctly, then
@ -210,6 +213,23 @@ var benchmark = func(label, f, arg...) {
var exit = func { fgcommand("exit") }
# print error vector as set by call(). By using call() one can execute
# code that catches "exceptions" (by a die() call or errors). The Nasal
# code doesn't abort in this case. Example:
#
# call(func { possibly_buggy() }, nil, var err = []);
# debug.printerror(err);
#
var printerror = func(err) {
if (!size(err))
return;
print(sprintf("%s at %s line %d", err[0], err[1], err[2]));
for (var i = 3; i < size(err); i += 2)
print(sprintf(" called from %s line %d", err[i], err[i + 1]));
}
if (getprop("/sim/logging/priority") != "alert") {
_setlistener("/sim/signals/nasal-dir-initialized", func { print(_c("32", "** NASAL initialized **")) });
_setlistener("/sim/signals/fdm-initialized", func { print(_c("36", "** FDM initialized **")) });