public void Visit(TryStatement statement) { try { statement.Statement.Accept(this); } catch (Exception e) { // there might be no catch statement defined if (statement.Catch != null) { JsException jsException = e as JsException; if (jsException == null) jsException = new JsException(Global.ErrorClass.New(e.Message)); // handle thrown exception assignment to a local variable: catch(e) if (statement.Catch.Identifier != null) { // if catch is called, Result contains the thrown value Assign(new MemberExpression(new PropertyExpression(statement.Catch.Identifier), null), jsException.Value); } statement.Catch.Statement.Accept(this); } else { throw; } } finally { if (statement.Finally != null) { JsObject catchScope = new JsObject(); statement.Finally.Statement.Accept(this); } } }
internal static JsException Create(JsConvert convert, JsError error) { string type = (string)convert.FromJsValue(error.Type); string resource = (string)convert.FromJsValue(error.Resource); string message = (string)convert.FromJsValue(error.Message); int line = error.Line; int column = error.Column + 1; // because zero based. JsObject nativeException = (JsObject)convert.FromJsValue(error.Exception); JsException exception; if (type == "SyntaxError") { exception = new JsSyntaxError(type, resource, message, line, column); } else { exception = new JsException(type, resource, message, line, column, nativeException); } return exception; }
public JScriptExceptionEventArgs(JsException exception, MinifierError error) { Error = error; Exception = exception; }
internal bool OnCompilerError(JsException se) { if (CompilerError != null && !m_settings.IgnoreAllErrors) { // format the error code string errorCode = "JS{0}".FormatInvariant((int)se.ErrorCode); if (m_settings != null && !m_settings.IgnoreErrorCollection.Contains(errorCode)) { // get the offending context string context = se.ErrorSegment; // if the context is empty, use the whole line if (!context.IsNullOrWhiteSpace()) { context = ": " + context; } CompilerError(this, new JScriptExceptionEventArgs(se, new MinifierError( se.IsError, se.Severity, GetSeverityString(se.Severity), errorCode, null, se.FileContext, se.Line, se.Column, se.EndLine, se.EndColumn, se.Message + context))); } } //true means carry on with compilation. return se.CanRecover; }
internal void HandleError(JsError errorId, bool forceToError) { if ((errorId != JsError.UndeclaredVariable && errorId != JsError.UndeclaredFunction) || !Document.HasAlreadySeenErrorFor(Code)) { var error = new JsException(errorId, this); if (forceToError) { error.IsError = true; } else { error.IsError = error.Severity < 2; } Document.HandleError(error); } }
public static void LogException(JsException exception) { if (exception != null) { try { Debug.Print(exception.ToString()); Logger.Warn(exception.Message); var error = new VLogClientSideError(exception); VLogErrorCode weberrorcode = VLog.GetWebErrorCodeOrDefault(exception.ErrorNumber.GetValueOrDefault(JsException.DefaultExceptionStatusCode), VLogErrorTypes.ClientSide); if (weberrorcode != null && !weberrorcode.ExcludeFromLogging) { if (VLog.OnCommitExceptionToServerRepository != null) { VLog.OnCommitExceptionToServerRepository(error); } } } catch (Exception ex) { // IMPORTANT! We swallow any exception raised during the // logging and send them out to the trace . The idea // here is that logging of exceptions by itself should not // be critical to the overall operation of the application. // The bad thing is that we catch ANY kind of exception, // even system ones and potentially let them slip by. Logger.Error(ex.ToString()); Debug.Print(ex.Message); } } }
//--------------------------------------------------------------------------------------- // HandleError // // Handle an error. There are two actions that can be taken when an error occurs: // - throwing an exception with no recovering action (eval case) // - notify the host that an error occurred and let the host decide whether or not // parsing has to continue (the host returns true when parsing has to continue) //--------------------------------------------------------------------------------------- internal void HandleError(JsException error) { if (m_parser != null) { if (!m_parser.OnCompilerError(error)) { throw new EndOfStreamException(); // this exception terminates the parser } } }