示例#1
0
 // The interpreter in which this AssocData instance is registered in.
 public void Dispose(Interp interp)
 {
     for (int i = Errors.Count - 1; i >= 0; i--)
     {
         BgError bgError = (BgError)Errors[i];
         Errors.RemoveAt(i);
         bgError.Cancel();
         bgError.ErrorMsg.Release(); bgError.ErrorMsg   = null;
         bgError.ErrorInfo.Release(); bgError.ErrorInfo = null;
         bgError.ErrorCode.Release(); bgError.ErrorCode = null;
     }
     BgerrorCmdObj.Release(); BgerrorCmdObj = null;
 }
示例#2
0
 internal void AddBgError()
 {
     BgError bgError = new BgError(this, Interp.GetNotifier());
     // The addErrorInfo() call below (with an empty string) ensures that errorInfo gets properly set.  It's needed in
     // cases where the error came from a utility procedure like Interp.getVar() instead of Interp.eval(); in these cases
     // errorInfo still won't have been set when this procedure is called.
     Interp.AddErrorInfo("");
     bgError.ErrorMsg = Interp.GetResult();
     bgError.ErrorInfo = null;
     try { bgError.ErrorInfo = Interp.GetVar("errorInfo", null, TCL.VarFlag.GLOBAL_ONLY); }
     catch (TclException) { } // Do nothing if var does not exist.
     bgError.ErrorCode = null;
     try { bgError.ErrorCode = Interp.GetVar("errorCode", null, TCL.VarFlag.GLOBAL_ONLY); }
     catch (TclException) { } // Do nothing if var does not exist.
     bgError.ErrorMsg.Preserve();
     bgError.ErrorInfo.Preserve();
     bgError.ErrorCode.Preserve();
     Errors.Add(bgError);
 }
示例#3
0
        internal void AddBgError()
        {
            BgError bgError = new BgError(this, Interp.GetNotifier());

            // The addErrorInfo() call below (with an empty string) ensures that errorInfo gets properly set.  It's needed in
            // cases where the error came from a utility procedure like Interp.getVar() instead of Interp.eval(); in these cases
            // errorInfo still won't have been set when this procedure is called.
            Interp.AddErrorInfo("");
            bgError.ErrorMsg  = Interp.GetResult();
            bgError.ErrorInfo = null;
            try { bgError.ErrorInfo = Interp.GetVar("errorInfo", null, TCL.VarFlag.GLOBAL_ONLY); }
            catch (TclException) { } // Do nothing if var does not exist.
            bgError.ErrorCode = null;
            try { bgError.ErrorCode = Interp.GetVar("errorCode", null, TCL.VarFlag.GLOBAL_ONLY); }
            catch (TclException) { } // Do nothing if var does not exist.
            bgError.ErrorMsg.Preserve();
            bgError.ErrorInfo.Preserve();
            bgError.ErrorCode.Preserve();
            Errors.Add(bgError);
        }
        public void  disposeAssocData(Interp interp)
        // The interpreter in which this AssocData
        // instance is registered in.
        {
            for (int i = errors.Count - 1; i >= 0; i--)
            {
                BgError bgErr = (BgError)errors[i];
                errors.RemoveAt(i);
                bgErr.cancel();

                bgErr.errorMsg.release();
                bgErr.errorMsg = null;
                bgErr.errorInfo.release();
                bgErr.errorInfo = null;
                bgErr.errorCode.release();
                bgErr.errorCode = null;
            }

            bgerrorCmdObj.release();
            bgerrorCmdObj = null;
        }
示例#5
0
            public override void ProcessIdleEvent()
            {
                // During the execution of this method, elements may be removed from the errors list (because a TCL.CompletionCode.BREAK was returned by the bgerror
                // command, or because the interp was deleted). We remove this BgError instance from the list first so that this instance won't
                // be deleted twice.
                SupportClass.VectorRemoveElement(EnclosingInstance.Errors, this);
                // Restore important state variables to what they were at the time the error occurred.
                try { EnclosingInstance.Interp.SetVar("errorInfo", null, ErrorInfo, TCL.VarFlag.GLOBAL_ONLY); }
                // Ignore any TclException's, possibly caused by variable traces on the errorInfo variable. This is compatible with the behavior of the Tcl C API.
                catch (TclException) { }
                try { EnclosingInstance.Interp.SetVar("errorCode", null, ErrorCode, TCL.VarFlag.GLOBAL_ONLY); }
                // Ignore any TclException's, possibly caused by variable traces on the errorCode variable. This is compatible with the behavior of the Tcl C API.
                catch (TclException) { }
                // Make sure, that the interpreter will surive the invocation of the bgerror command.
                EnclosingInstance.Interp.preserve();
                try
                {
                    // Invoke the bgerror command.
                    TclObject[] argv = new TclObject[2];
                    argv[0] = EnclosingInstance.BgerrorCmdObj;
                    argv[1] = ErrorMsg;
                    Parser.EvalObjv(EnclosingInstance.Interp, argv, 0, TCL.EVAL_GLOBAL);
                }
                catch (TclException e)
                {
                    switch (e.GetCompletionCode())
                    {
                    case TCL.CompletionCode.ERROR:
                        try
                        {
                            Channel chan   = TclIO.GetStdChannel(StdChannel.STDERR);
                            var     interp = EnclosingInstance.Interp;
                            if (EnclosingInstance.Interp.GetResult().ToString().Equals("\"bgerror\" is an invalid command name or ambiguous abbreviation"))
                            {
                                chan.Write(interp, ErrorInfo);
                                chan.Write(interp, "\n");
                            }
                            else
                            {
                                chan.Write(interp, "bgerror failed to handle background error.\n");
                                chan.Write(interp, "    Original error: ");
                                chan.Write(interp, ErrorMsg);
                                chan.Write(interp, "\n");
                                chan.Write(interp, "    Error in bgerror: ");
                                chan.Write(interp, EnclosingInstance.Interp.GetResult());
                                chan.Write(interp, "\n");
                            }
                            chan.Flush(EnclosingInstance.Interp);
                        }
                        catch (TclException) { }    // Ignore.
                        catch (IOException) { }     // Ignore, too.
                        break;

                    case TCL.CompletionCode.BREAK:
                        for (int i = EnclosingInstance.Errors.Count - 1; i >= 0; i--)
                        {
                            BgError bgError = (BgError)EnclosingInstance.Errors[i];
                            EnclosingInstance.Errors.RemoveAt(i);
                            bgError.Cancel();
                            bgError.ErrorMsg.Release(); bgError.ErrorMsg   = null;
                            bgError.ErrorInfo.Release(); bgError.ErrorInfo = null;
                            bgError.ErrorCode.Release(); bgError.ErrorCode = null;
                        }
                        break;
                    }
                }
                EnclosingInstance.Interp.release();
                ErrorMsg.Release(); ErrorMsg   = null;
                ErrorInfo.Release(); ErrorInfo = null;
                ErrorCode.Release(); ErrorCode = null;
            }