public void SetControlsFromException() { lineNumber = -1; isTemplate = true; lastErrors.Clear(); if (exception is ZeusExecutionException) { ZeusExecutionException executionException = exception as ZeusExecutionException; int numErrors = executionException.Errors.Length; if (numErrors > 1) { this.panelErrors.Visible = true; this._max = executionException.Errors.Length - 1; this.UpdateErrorLabel(); } else { this.panelErrors.Visible = false; } this.labelFile.Text = "Template Filename"; this.labelTitle.Text = "Scripting Error"; this.labelSource.Text = "Source"; this.labelMessage.Text = "Error Text"; this.labelMethod.Text = "Error Number"; this.labelStackTrace.Text = "Scripting Errors and Warnings:"; this.textBoxExceptionType.Text = "Scripting Error"; IZeusExecutionError error = executionException.Errors[this._index]; if (!error.IsWarning) { this.textBoxFile.Text = error.FileName; this.textBoxLine.Text = error.Line.ToString(); this.textBoxColumn.Text = error.Column.ToString(); this.textBoxSource.Text = error.Source; this.textBoxMessage.Text = error.Message + " " + error.Description; this.textBoxMethod.Text = error.Number; this.lastFileName = error.FileName; this.lineNumber = error.Line; } foreach (IZeusExecutionError tmperror in executionException.Errors) { // Create error string for the log StringBuilder builder = new StringBuilder(); builder.Append(tmperror.IsWarning ? "[Warning] " : "[Error] "); builder.Append(tmperror.Source); builder.Append(" (" + tmperror.Line + ", " + tmperror.Column + ") "); builder.Append(tmperror.Number + ": "); builder.Append(tmperror.Message); if (tmperror.StackTrace != string.Empty) { builder.Append("\r\nStack Trace"); builder.Append(tmperror.StackTrace); } if (tmperror == error) { this.textBoxStackTrace.Text = builder.ToString(); } lastErrors.Add(builder.ToString()); } isTemplate = executionException.IsTemplateScript; } else if (exception is ZeusDynamicException) { ZeusDynamicException zde = exception as ZeusDynamicException; this.textBoxFile.Text = string.Empty; this.textBoxLine.Text = string.Empty; this.textBoxColumn.Text = string.Empty; this.textBoxSource.Text = string.Empty; this.textBoxMessage.Text = zde.Message; this.textBoxMethod.Text = string.Empty; this.textBoxStackTrace.Text = string.Empty; this.textBoxExceptionType.Text = zde.GetType().Name; this.labelTitle.Text = zde.DynamicExceptionTypeString; this.labelMethod.Text = string.Empty; // Create error string for the log lastErrors.Add("[" + this.textBoxExceptionType.Text + "] " + zde.DynamicExceptionTypeString + " - " + zde.Message); } else { StackTrace stackTrace = null; StackFrame stackFrame = null; Exception baseException = exception.GetBaseException(); try { stackTrace = new StackTrace(baseException, true); if (stackTrace.FrameCount > 0) { stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); } } catch { stackTrace = null; } if (stackFrame != null) { this.textBoxFile.Text = stackFrame.GetFileName(); this.textBoxLine.Text = stackFrame.GetFileLineNumber().ToString(); this.textBoxColumn.Text = stackFrame.GetFileColumnNumber().ToString(); } this.textBoxSource.Text = baseException.Source; this.textBoxMessage.Text = baseException.Message; this.textBoxMethod.Text = baseException.TargetSite.ToString(); this.textBoxStackTrace.Text = baseException.StackTrace; this.textBoxExceptionType.Text = baseException.GetType().Name; this.labelTitle.Text = "System Exception"; this.labelMethod.Text = "Method"; // Create error string for the log lastErrors.Add("[" + this.textBoxExceptionType.Text + "] " + this.textBoxSource.Text + "(" + this.textBoxLine.Text + ", " + this.textBoxColumn.Text + ") " + this.textBoxMessage.Text); } }
public static List <IMyGenError> CreateErrors(params Exception[] exceptions) { MyGenError error; List <IMyGenError> myGenErrors = new List <IMyGenError>(); foreach (Exception loopex in exceptions) { Exception ex = loopex, bex = ex.GetBaseException(); if (ex is ZeusRuntimeException) { ZeusRuntimeException zrex = ex as ZeusRuntimeException; if (bex is ZeusExecutionException) { ZeusExecutionException zeex = bex as ZeusExecutionException; foreach (IZeusExecutionError zee in zeex.Errors) { error = new MyGenError(); error.errorClass = MyGenErrorClass.Template; error.templateFileName = zrex.Template.FilePath + zrex.Template.FileName; error.TemplateIdentifier = zrex.Template.UniqueID; error.IsTemplateCodeSegment = zrex.IsTemplateScript; PopulateErrorFromZeusExecError(error, zee); myGenErrors.Add(error); } } else { error = new MyGenError(); error.errorClass = MyGenErrorClass.Template; error.templateFileName = zrex.Template.FilePath + zrex.Template.FileName; error.TemplateIdentifier = zrex.Template.UniqueID; error.IsTemplateCodeSegment = zrex.IsTemplateScript; error.isRuntime = true; PopulateErrorFromException(error, bex); myGenErrors.Add(error); } } else if (ex is ZeusExecutionException) { ZeusExecutionException zeex = ex as ZeusExecutionException; foreach (IZeusExecutionError zee in zeex.Errors) { error = new MyGenError(); error.errorClass = MyGenErrorClass.Template; error.templateFileName = zeex.Template.FilePath + zeex.Template.FileName; error.TemplateIdentifier = zeex.Template.UniqueID; error.IsTemplateCodeSegment = zeex.IsTemplateScript; PopulateErrorFromZeusExecError(error, zee); myGenErrors.Add(error); } } else { if (bex == null) { bex = ex; } error = new MyGenError(); error.errorClass = MyGenErrorClass.Application; PopulateErrorFromException(error, bex); myGenErrors.Add(error); } } return(myGenErrors); }