コード例 #1
0
        private void ErrorHandle(Exception ex, PersistentObject obj, string strMessage)
        {
            if (ex is PersistenceLayerException)
            {
                throw ex;
            }

            if (obj == null)
            {
                Assert.Fail(Error.DatabaseUnknownError, ex.Message + (strMessage != null ? strMessage : ""));
            }

            IPersistenceProvider rdb = this.GetDatabase(GetDatabaseName(obj));

            string strErr = "";
            Error  error  = rdb.ErrorHandler(ex, out strErr);

            if (error == Error.Unknown)
            {
                if (ex is InvalidCastException)
                {
                    switch (ex.TargetSite.Name)
                    {
                    case "RetrievePrivate":
                        strErr = obj.GetClassName() + "A type conversion exception occurred while the object was executing the Retrive() method!";
                        Assert.Fail(Error.Unknown, strErr);
                        break;

                    default:
                        Assert.Fail(Error.Unknown);
                        break;
                    }
                }
                Assert.Fail(Error.Unknown, ex.Message);
            }
            else
            {
                switch (error)
                {
                case Error.NotAllowDataNull:
                    strErr = obj.GetClassName() + "Some properties cannot be null";
                    Assert.Fail(error, strErr);
                    break;

                case Error.DataTypeNotMatch:
                    strErr = obj.GetClassName() + "Some attribute data types are not compatible with database data types";
                    Assert.Fail(error, strErr);
                    break;

                case Error.AutoValueOn:
                    strErr = obj.GetClassName() + "There is an automatic number attribute, you cannot specify a specific value";
                    Assert.Fail(error, strErr);
                    break;

                case Error.RestrictError:
                    strErr = "Trying to" + obj.GetClassName() + "Object operation, operation is terminated due to constraint mechanism";
                    Assert.Fail(error, strErr);
                    break;

                case Error.RequireAttribute:
                    strErr = "Trying to" + obj.GetClassName() + "Object operation, but the property is not specified or is null";
                    Assert.Fail(error, strErr);
                    break;

                case Error.NotUnique:
                    strErr = obj.GetClassName() + "The data of the object or its associated object conflicts with the existing data";
                    Assert.Fail(error, strErr);
                    break;

                case Error.DataTooLong:
                    strErr = obj.GetClassName() + "Data exceeds database capacity";
                    Assert.Fail(error, strErr);
                    break;

                case Error.NotAllowStringEmpty:
                    strErr = obj.GetClassName() + "The attribute in the character cannot be zero length";
                    Assert.Fail(error, strErr);
                    break;
                }
                strErr = obj.GetClassName() + "Object operation error," + ex.Message + (strMessage != null ? strMessage : "");
                Assert.Fail(error, strErr);
            }
        }