コード例 #1
0
		public void BuildExceptionMessage()
		{
			string resources = "FirebirdSql.Data.Common.Resources.isc_error_msg";			

			StringBuilder builder = new StringBuilder();
			ResourceManager rm = new ResourceManager(resources, Assembly.GetExecutingAssembly());

			this.errorCode = (this.Errors.Count != 0) ? this.Errors[0].ErrorCode : 0;

			for (int i = 0; i < this.Errors.Count; i++)
			{
				if (this.Errors[i].Type == IscCodes.isc_arg_gds ||
					this.Errors[i].Type == IscCodes.isc_arg_warning)
				{
					int code = this.Errors[i].ErrorCode;
					string message = null;

					try
					{
						message = rm.GetString(code.ToString());
					}
					catch
					{
						message = null;
					}
					finally
					{
						if (message == null)
						{
							message = String.Format(CultureInfo.CurrentCulture, "No message for error code {0} found.", code);
						}
					}

					ArrayList param = new ArrayList();

					int index = i + 1;

					while (index < this.Errors.Count && this.Errors[index].IsArgument)
					{
						param.Add(this.Errors[index++].StrParam);
						i++;
					}

					object[] args = (object[])param.ToArray(typeof(object));

					try
					{
						if (code == IscCodes.isc_except)
						{
							// Custom exception	add	the	first argument as error	code
							this.errorCode = Convert.ToInt32(args[0], CultureInfo.InvariantCulture);
						}
						else
						{
							if (builder.Length > 0)
							{
								builder.Append("\n");
							}

							builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
						}
					}
					catch
					{
						message = String.Format(CultureInfo.CurrentCulture, "No message for error code {0} found.", code);

						builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
					}
				}
			}

			// Update error	collection only	with the main error
			IscError mainError = new IscError(this.errorCode);
			mainError.Message = builder.ToString();

			this.errors = new IscErrorCollection();
			this.Errors.Add(mainError);

			// Update exception	message
			this.message = builder.ToString();
		}
コード例 #2
0
        public void BuildExceptionMessage()
        {
            string resources = "FirebirdSql.Data.Common.Resources.isc_error_msg";

            StringBuilder   builder = new StringBuilder();
            ResourceManager rm      = new ResourceManager(resources, Assembly.GetExecutingAssembly());

            this.errorCode = (this.Errors.Count != 0) ? this.Errors[0].ErrorCode : 0;

            for (int i = 0; i < this.Errors.Count; i++)
            {
                if (this.Errors[i].Type == IscCodes.isc_arg_gds ||
                    this.Errors[i].Type == IscCodes.isc_arg_warning)
                {
                    int    code    = this.Errors[i].ErrorCode;
                    string message = null;

                    try
                    {
                        message = rm.GetString(code.ToString());
                    }
                    catch
                    {
                        message = null;
                    }
                    finally
                    {
                        if (message == null)
                        {
                            message = String.Format(CultureInfo.CurrentCulture, "No message for error code {0} found.", code);
                        }
                    }

                    ArrayList param = new ArrayList();

                    int index = i + 1;

                    while (index < this.Errors.Count && this.Errors[index].IsArgument)
                    {
                        param.Add(this.Errors[index++].StrParam);
                        i++;
                    }

                    object[] args = (object[])param.ToArray(typeof(object));

                    try
                    {
                        if (code == IscCodes.isc_except)
                        {
                            // Custom exception	add	the	first argument as error	code
                            this.errorCode = Convert.ToInt32(args[0], CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            if (builder.Length > 0)
                            {
                                builder.Append("\n");
                            }

                            builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
                        }
                    }
                    catch
                    {
                        message = String.Format(CultureInfo.CurrentCulture, "No message for error code {0} found.", code);

                        builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
                    }
                }
            }

            // Update error	collection only	with the main error
            IscError mainError = new IscError(this.errorCode);

            mainError.Message = builder.ToString();

            this.errors = new IscErrorCollection();
            this.Errors.Add(mainError);

            // Update exception	message
            this.message = builder.ToString();
        }