While working with someone else's "utility class," David decided to have a little fun and turn on compiler warnings. It turns out that the compiler is actually sort of good at catching weird abuses in Java.

 

As he put it,
I turned on some additional compiler warnings, including one to warn about undocumented empty blocks, and it complained about the catch block below. Catching and swallowing exceptions is all too common on this project (as are the completely useless javadoc comments that don't actually document anything), but this is the first time I've seen someone...
Actually, why don't I just show you?

 

 

  /**
   * Insert the method's description here.
   * Creation date: (02/15/00 6:27:04 PM)
   * @param obj java.lang.Object
   * @param buf java.lang.StringBuffer
   */
  protected
  static
  void doWork(Object obj, StringBuffer buf) {
      try {
          String lastTag = "</" + obj.getClass().getName() + ">";
          int position = buf.toString().lastIndexOf( lastTag );
          String description = getDescription( obj );
          buf.insert( position, description );
      }
      catch (Exception e) {
          try {
              throw new Exception("Error inserting description!");
          }
          catch (Exception ex) {
          }
      }
  }

 

I don't really know what this function is for; neither does javadoc, so I don't feel so bad. I guess the point is this: if at first you don't succeed, try-catch again.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!