Пример #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="exType">Type of ExceptionType.</param>
 /// <param name="message">The error message for this exception.</param>
 /// <param name="innerException">The inner exception that is wrapped in this exception.</param>
 public CustomException(ExceptionType exType, string message, System.Exception innerException)
     : base(message, innerException)
 {
     //this.CustomMessage = rm.GetString(exType.ToString());
     this.CustomMessage = ExpResources.ExpResources.ResourceManager.GetString(exType.ToString()) ?? "[[" + exType.ToString() + "]]";
     this.ExceptionType = exType.ToString();
 }
        public ExpectedExceptionModel Build(AttributeData attributeData)
        {
            if (MatchType == null && ExpectedMessage != null)
            {
                MatchType = MemberAccess(IdentifierName("MessageMatch"), "Exact");
            }

            if (ExceptionName != null && ExceptionType != null)
            {
                throw new InvalidOperationException(
                          "Unable to convert ExpectedException attribute, "
                          + $"both a name: {ExceptionName.ToString()} and a type: {ExceptionType.ToString()} are specified");
            }

            if (ExceptionName is LiteralExpressionSyntax nameLiteral && ExceptionType == null)
            {
                var value = nameLiteral.Token.ValueText;
                ExceptionType = TypeOfExpression(IdentifierName(value));
            }

            if (attributeData == null)
            {
                throw new InvalidOperationException($"Required field {nameof(attributeData)} is null.");
            }

            ExceptionType ??= IdentifierName("Exception");

            return(new ExpectedExceptionModel(
                       attributeData,
                       ExceptionType,
                       UserMessage,
                       ExpectedMessage,
                       MatchType));
        }
Пример #3
0
 /// <summary>
 /// Throw Virtual Machine Exception (RUNError)
 /// </summary>
 /// <param name="message">Exception message with big first letter</param>
 /// <param name="position">Position where throwed exception</param>
 /// <param name="type">Type of exception</param>
 public static void ThrowVMException(string message, int position, ExceptionType type)
 {
     Console.BackgroundColor = ConsoleColor.DarkRed;
     Console.Error.WriteLine($"{type.ToString()}. Exception in position {position}. {message}");
     Console.BackgroundColor = ConsoleColor.Black;
     //Environment.Exit(((int) type) + 2); //for try-catch feauture
 }
Пример #4
0
        private static string errorDescription(int errorCode, ExceptionType type)
        {
            string value;
            string type_ErrorCode;

            if (errorCode < 200)
            {
                type_ErrorCode = errorCode.ToString();
            }
            else
            {
                type_ErrorCode = $"{type.ToString()}{errorCode}";
            }

            errorTable.TryGetValue(type_ErrorCode, out value);
            return(value);
        }
Пример #5
0
        private static ErrorMessage CreateErrorMessage(NotificationAction action, ExceptionType errorType, Exception error = null)
        {
            ErrorMessage obj = new ErrorMessage()
            {
                Action = action
            };

            if (error != null)
            {
                obj.Error.HelpLink       = error.HelpLink;
                obj.Error.StackTrace     = error.StackTrace;
                obj.Error.Source         = error.Source;
                obj.Error.Message        = error.Message;
                obj.Error.InnerException = (error.InnerException == null) ? "" : error.InnerException.Message;
            }
            obj.Error.Type = errorType.ToString();
            return(obj);
        }
Пример #6
0
        public QStrategyException(string message, Exception innerException, ExceptionType exceptionType, string sourceLocation)
            : base(message, innerException)
        {
            this.exceptionType = exceptionType;
            this.sourceLocation = sourceLocation;
            string messageDetail = message;
            message = exceptionType.ToString();
            if (innerException != null)
            {
                while (innerException.InnerException != null)
                {
                    innerException = innerException.InnerException;
                }
                message = innerException.Message;
                messageDetail = innerException.StackTrace;
            }

            string messageLog = string.Format("ExceptionType: {0}, Source:{1}, Exception:{2} MessageDetails: {3}", ExceptionType.ToString(), sourceLocation, message, messageDetail);
            LogUtil.WriteLog(LogLevel.ERROR, messageLog);
        }
        /// <summary>
        /// Gets the exception list in a readable form for restful consumption.
        /// </summary>
        /// <returns></returns>
        public List <ExceptionListItem> GetExceptionList()
        {
            var collection = new List <ExceptionListItem>();

            if (InnerExceptions != null && InnerExceptions.Any())
            {
                InnerExceptions.ForEach(ex => collection.Add(new ExceptionListItem()
                {
                    Name = ex.Message, Type = ex.ExceptionType.ToString()
                }));
            }
            else
            {
                collection.Add(new ExceptionListItem()
                {
                    Name = Message, Type = ExceptionType.ToString()
                });
            }

            return(collection);
        }
Пример #8
0
        private static void HandleException(ExceptionType exceptionType, Exception exception, string source)
        {
            using (var eventLog = new EventLog())
            {
                if (!System.Diagnostics.EventLog.SourceExists(source))
                {
                    System.Diagnostics.EventLog.CreateEventSource(source, "Application");
                }
                eventLog.Source = source;
                eventLog.Log = "Application";

                StringBuilder message = new StringBuilder();
                message.AppendLine("A " + source + " " + exceptionType.ToString() + " occurred with the following details:");
                message.AppendLine();
                message.AppendLine(exception.Message);
                if (exception.InnerException != null)
                {
                    message.AppendLine();
                    message.AppendLine("InnerException:");
                    message.AppendLine(exception.InnerException.ToString());
                }
                message.AppendLine();
                message.AppendLine("StackTrace:");
                message.AppendLine(exception.StackTrace);

                eventLog.WriteEntry(message.ToString(), System.Diagnostics.EventLogEntryType.Error);

                StringBuilder returnMessage = new StringBuilder();
                returnMessage.AppendLine("Exception:");
                returnMessage.AppendLine(exception.Message);
                if (exception.InnerException != null)
                {
                    returnMessage.AppendLine();
                    returnMessage.AppendLine("Inner Exception:");
                    returnMessage.AppendLine(exception.InnerException.Message);
                }
            }
        }
        /// <summary>
        /// 新增日志
        /// </summary>
        /// <param name="exceptionType"></param>
        /// <param name="message"></param>
        /// <param name="remark"></param>
        public void AddLog(ExceptionType exceptionType, Exception ex, string remark = "")
        {
            try
            {
                Sys_Exception_Log entity = new Sys_Exception_Log()
                {
                    TraceIdentifier = CatContext.HttpContext.TraceIdentifier,
                    ExceptionType   = exceptionType.ToString(),
                    Message         = ex.Message,
                    StackTrace      = ex.StackTrace,
                    InnerException  = ex.InnerException.ToStr(),
                    Source          = ex.Source,
                    TargetSite      = ex.TargetSite.ToStr(),
                    Remark          = remark,
                };

                entity.Create_Time = entity.Create_Time ?? DateTime.Now;
                base.InsertOne(entity);
            }
            catch (Exception ex2)
            {
                FileHelper.CreateFiles($"~/log/exception/Sys_Exception_Log.{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.log", ex2);
            }
        }
Пример #10
0
 public static string Message(this ExceptionType type)
 => Resources.ResourceManager.GetString(type.ToString()) ?? type.ToString();
Пример #11
0
 public static void ConsoleWarn(ExceptionType type)
 {
     Console.WriteLine(type.ToString());
 }
Пример #12
0
        public static void Throw(object entityObj = null, string reason = null, ExceptionType exceptionType = ExceptionType.None, bool GroupFailed = false)
        {
            //What should be happen here
            if (entityObj == null)
            {
                throw new System.Exception(reason);
            }
            var entity = (BaseEntity)entityObj;

            throw new System.Exception(string.Format("{0} {1} (ID: {2}) failed. Reason: {3} . {4}", exceptionType.ToString(), entityObj.GetType().Name, entity.Id, reason, GroupFailed ? " All operations canceled" : ""));
        }
Пример #13
0
 private void CheckExceptionType(ExceptionType type, Action action)
 {
     try {
         action.Invoke();
     }
     catch (ErrReportException e) {
         if (type == ExceptionType.Regular) {
             return;
         }
         Assert.Fail("Got and exption type {0} while expecting ", e.GetType().Name, type.ToString());
     }
     catch (FaultException<ErrReport> e) {
         if (type == ExceptionType.Fault) {
             return;
         }
         Assert.Fail("Got and exption type {0} while expecting ", e.GetType().Name, type.ToString());
     }
     catch (Exception e) {
         Assert.Fail("Got and exption type {0} while expecting ", e.GetType().Name, type.ToString());
     }
 }
Пример #14
0
 public override string ToString()
 {
     return($@"Error occured during {SyncStage.ToString()} of type {ExceptionType.ToString()}: {Message}");
 }
Пример #15
0
 public void BuildErrorMessage()
 {
     _exceptionMessage  = _exceptionType.ToString() + " Exception thrown from '" + _className + "' Class at '" + _function + "' Function." + Environment.NewLine;
     _exceptionMessage += " " + base.Message;
 }
Пример #16
0
        public static void ThrowException(ExceptionType exceptionType, string extraMessage = null)
        {
            switch (exceptionType)
            {
            case ExceptionType.InvalidFileInput:
                throw new System.IO.InvalidDataException($"{SR.ResourceManager.GetString(exceptionType.ToString())}-{extraMessage}");

            case ExceptionType.InvalidDataAlignment:
                throw new DataMisalignedException(extraMessage);

            default:
                throw new InvalidOperationException($"Unknown exception type {exceptionType}");
            }
        }
Пример #17
0
 public static Exception GetException(ExceptionType type, params object[] additionalInfo)
 {
     return(new Exception($"[{type.ToString().ToUpper()}] {string.Format(Messages[type], additionalInfo)}"));
 }
Пример #18
0
 public TranslationException(ExceptionType eType, string message)
     : base(eType.ToString() + ": " + message)
 {
 }
 public TranslationException(ExceptionType eType, string message)
   : base(eType.ToString() + ": " + message) {
 }
Пример #20
0
 public CustomExeption(ExceptionType type, string message, string description)
     : base(message)
 {
     this.ExceptionType = type.ToString();
     this.Description   = description;
 }
Пример #21
0
        public static void WriteExceptionInDB(Exception ex, ExceptionLevel el, ExceptionType et)
        {
            try
            {
                string _query          = string.Empty;
                string _source         = ex.Source;
                string _memberType     = ex.TargetSite.MemberType.ToString();
                string _method         = ex.TargetSite.Name;
                string _form           = ex.TargetSite.DeclaringType.Name;
                string _message        = ex.Message;
                string _stackTrace     = ex.StackTrace;
                string _exceptionLayer = el.ToString();
                string _exceptionType  = et.ToString();
                if (DBConfigHelper.Provider == DatabaseProviderType.Sql)
                {
                    SqlParameter[] _objParameters = new SqlParameter[10];
                    //_objParameters[0] = new SqlParameter("SNO", System.Data.SqlDbType.BigInt);
                    //_objParameters[0].Value = GetMaxId();
                    _objParameters[0]       = new SqlParameter("@EXCEPTION_LAYER", System.Data.SqlDbType.VarChar);
                    _objParameters[0].Value = _exceptionLayer;
                    _objParameters[1]       = new SqlParameter("@SOURCE_LAYER", System.Data.SqlDbType.NVarChar);
                    _objParameters[1].Value = _source;
                    _objParameters[2]       = new SqlParameter("@STACKTRACE", System.Data.SqlDbType.NVarChar);
                    _objParameters[2].Value = _stackTrace;
                    _objParameters[3]       = new SqlParameter("@ERROR_MESSAGE", System.Data.SqlDbType.VarChar);
                    _objParameters[3].Value = _message;
                    _objParameters[4]       = new SqlParameter("@MEMBER_TYPE", System.Data.SqlDbType.VarChar);
                    _objParameters[4].Value = _memberType;
                    _objParameters[5]       = new SqlParameter("@METHOD", System.Data.SqlDbType.VarChar);
                    _objParameters[5].Value = _method;
                    _objParameters[6]       = new SqlParameter("@FORM", System.Data.SqlDbType.VarChar);
                    _objParameters[6].Value = _form;
                    _objParameters[7]       = new SqlParameter("@EXCEPTION_DATETIME", System.Data.SqlDbType.DateTime);
                    _objParameters[7].Value = DateTime.Now.ToString("dd-MMM-yyyy");
                    _objParameters[8]       = new SqlParameter("@CLIENT_IP", System.Data.SqlDbType.VarChar);
                    _objParameters[8].Value = "";
                    _objParameters[9]       = new SqlParameter("@EXCEPTION_TYPE", System.Data.SqlDbType.VarChar);
                    _objParameters[9].Value = _exceptionType;

                    SqlConnection con  = new SqlConnection(_dbConnectionString);
                    SqlCommand    _cmd = new SqlCommand();
                    foreach (var param in _objParameters)
                    {
                        _cmd.Parameters.Add(param);
                    }
                    _cmd.Connection  = con;
                    _cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    _cmd.CommandText = "spSysExceptionLog";
                    if (_cmd.Connection.State == System.Data.ConnectionState.Closed)
                    {
                        _cmd.Connection.Open();
                        int _effectedRow = _cmd.ExecuteNonQuery();
                        _cmd.Connection.Close();
                        _cmd.Dispose();
                    }
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }