handle throw of non-Errors gracefully

This commit is contained in:
alexlamsl 2019-10-17 05:04:17 +08:00
parent 7b5350b459
commit 8bf62b61d7

View File

@ -959,14 +959,19 @@ if (require.main !== module) {
return; return;
} }
function writeln(stream, msg) {
if (typeof msg != "undefined") {
stream.write(typeof msg == "string" ? msg : msg.stack || "" + msg);
}
stream.write("\n");
}
function println(msg) { function println(msg) {
if (typeof msg != "undefined") process.stdout.write(typeof msg == "string" ? msg : msg.stack); writeln(process.stdout, msg);
process.stdout.write("\n");
} }
function errorln(msg) { function errorln(msg) {
if (typeof msg != "undefined") process.stderr.write(typeof msg == "string" ? msg : msg.stack); writeln(process.stderr, msg);
process.stderr.write("\n");
} }
function try_beautify(code, toplevel, result, printfn) { function try_beautify(code, toplevel, result, printfn) {