internal void errorPrint(RThread th, Exception errinfo) { if (errinfo is eTagJump) { errorPrint(th); return; } th.errorPos(); string tp = errinfo.GetType().ToString(); int n = tp.LastIndexOf('.'); if (n >= 0) tp = tp.Substring(n + 1); if (tp[0] == 'e') tp = tp.Substring(1); System.Console.Error.WriteLine(String.Format(": {0}: ({1})", errinfo.Message, tp)); RArray ra = Backtrace(-1); printBacktrace(ra); #if EXCEP_TRACE warning(errinfo.StackTrace); #endif }
/* private void ParserAppendPrint(RThread th, RNode node) { uint id = intern("$_"); node = RNode.block_append(th, node, new RNFCall(null, intern("print"), new RNArray(null, new RNGVar(id, global_entry(id))))); } */ /* public void Run() { bool thCreated; RThread th = GetCurrentContext(out thCreated); if (th.CompileFailed) return; Tag.TAG state = Tag.TAG.EMPTY; th.PushTag(Tag.TAG.PROT_NONE); th.PushIter(ITER.NOT); try { EvalNode(topSelf, th.evalTree, th); } catch (eTagJump tj) { #if _DEBUG System.Console.WriteLine(tj.StackTrace); #endif state = tj.state; if (th.CurrentTag.tag != Tag.TAG.EMPTY) errorPrint(th); } catch (Exception ex) { #if _DEBUG System.Console.WriteLine(ex.StackTrace); #endif state = Tag.TAG.RAISE; if (th.CurrentTag.tag != Tag.TAG.EMPTY) errorPrint(th, ex); } th.PopIter(); th.PopTag(false); if (thCreated) ClearContext(th); } */ internal void errorPrint(RThread th) { if (th.errInfo == null) return; ////th.PushTag(Tag.TAG.PROT_NONE); RArray errat; try { errat = th.errInfo.Backtrace; } catch { errat = null; } ////th.PopTag(false); if (errat == null) { if (th.file != null) System.Console.Error.Write(String.Format("{0}:{1}", th.file, th.line)); else System.Console.Error.Write(String.Format("{0}", th.line)); } else if (errat.Count == 0) { th.errorPos(); } else { if (errat[0] == null) th.errorPos(); else System.Console.Error.Write(errat[0].ToString()); } string einfo = String.Empty; RMetaObject eClass = ClassOf(th.errInfo); ////th.PushTag(Tag.TAG.PROT_NONE); try { einfo = RString.AsString(this, th.errInfo); } catch { } ////Tag tag2 = th.PopTag(true); if (eClass == eRuntimeError && einfo.Length == 0) { System.Console.Error.WriteLine(": unhandled exception"); } else { string epath = eClass.ClassPath; if (einfo.Length == 0) { System.Console.Error.WriteLine(": " + epath); } else { if (epath[0] == '#') epath = null; System.Console.Error.Write(": " + einfo); if (epath != null) { System.Console.Error.WriteLine(" (" + epath + ")"); } } } printBacktrace(errat); }