Пример #1
0
        public void AddExceptions()
        {
            ConstraintCollection col = _table.Constraints;

            //null
            try {
                col.Add(null);
                Assert.Fail("B1: Failed to throw ArgumentNullException.");
            } catch (ArgumentNullException) {
            } catch (AssertionException exc) {
                throw exc;
            } catch {
                Assert.Fail("A1: Wrong exception type");
            }

            //duplicate name
            try {
                _constraint1.ConstraintName = "Dog";
                _constraint2.ConstraintName = "dog";                 //case insensitive
                col.Add(_constraint1);
                col.Add(_constraint2);
                col.Remove(_constraint2);                  // only for !1.0
                col.Remove(_constraint1);
            }
            catch (AssertionException exc) {
                throw exc;
            }

/* Don't use such catch. They cover our eyes from the exact exception location.
 *                      catch (Exception exc)
 *                      {
 *                              Assert.Fail("A2: Wrong exception type. " + exc.ToString());
 *                      }
 */
            //Constraint Already exists
            try {
                col.Add(_constraint1);
                col.Remove(_constraint1);
            } catch (ArgumentException) {
            } catch (AssertionException exc) {
                throw exc;
            } catch {
                Assert.Fail("A3: Wrong exception type");
            }
        }
Пример #2
0
 // <Snippet1>
 private void RemoveConstraint(ConstraintCollection constraints,
                               Constraint constraint)
 {
     if (constraints.Contains(constraint.ConstraintName))
     {
         if (constraints.CanRemove(constraint))
         {
             constraints.Remove(constraint.ConstraintName);
         }
     }
 }
Пример #3
0
 // <Snippet1>
 public static void RemoveConstraint(
     ConstraintCollection constraints, Constraint constraint)
 {
     try
     {
         if (constraints.Contains(constraint.ConstraintName))
         {
             if (constraints.CanRemove(constraint))
             {
                 constraints.Remove(constraint.ConstraintName);
             }
         }
     }
     catch (Exception e)
     {
         // Process exception and return.
         Console.WriteLine("Exception of type {0} occurred.",
                           e.GetType());
     }
 }