1 Reply Latest reply: Mar 25, 2011 12:09 PM by 796440 RSS

    RuntimeException

    EdChouaffe
      Hi Guys.

      Is there any good reasons why an RuntimeException is not thrown although it should?
      Look at the following code snippset:
      Note: colConstraints is a HashMap object.
      Set<String> newValueSet = .... (here is the object initialized with some values)
      for (String key : newValuesSet) {
                          if (colConstraints.containsKey(key)) {
                               System.out.println(colConstraints + "  " + key);
                               throw new RuntimeException(
                                         "SQLQueryBuilder.UpdateQuery: Misplacement " + key
                                                   + " cannot be a primary or foreign key");
                          }
                     }
      I wonder why I dont get any error thrown even though there are cases where key is contained within colConstraints.
      Best regrads.

      Edmond
        • 1. Re: RuntimeException
          796440
          EdChouaffe wrote:
          Hi Guys.

          Is there any good reasons why an RuntimeException is not thrown although it should?
          It's not thrown because it shouldn't be. You need to check your assumptions.
          Look at the following code snippset:
          Note: colConstraints is a HashMap object.
          Set<String> newValueSet = .... (here is the object initialized with some values)
          for (String key : newValuesSet) {
                              if (colConstraints.containsKey(key)) {
                                   System.out.println(colConstraints + "  " + key);
                                   throw new RuntimeException(
                                             "SQLQueryBuilder.UpdateQuery: Misplacement " + key
                                                       + " cannot be a primary or foreign key");
                              }
                         }
          I wonder why I dont get any error thrown even though there are cases where key is contained within colConstraints.
          colConstraints doesn't contain any of those keys. If it did, you would get the printout, and the exception would be thrown. Perhaps you didn't put what you though you did into colConstraints. Perhaps colConstraints contains keys of some type other than String. Perhaps you are getting the exception and smothering it elsewhere. Impossible to say with so little information.

          However, I know for certain that containsKey() does work, and the if statement does work. So if the exception is not getting thrown, then colConstraints definitely does not contain that key.