Commits

David Carr  committed 3761cb8

api: use AggregateBuilderException instead of IllegalStateException for run

  • Participants
  • Parent commits 232f151

Comments (0)

Files changed (1)

File src/main/java/org/bitbucket/davidm24/mongodb/aggregate/AggregateBuilder.java

  * @see <a href="http://docs.mongodb.org/manual/reference/aggregation/">Aggregation Framework Reference</a>
  * @since 0.1.0
  */
-public class AggregateBuilder {    
+public class AggregateBuilder {
+    /**
+     * A violation of the contract of AggregateBuilder.
+     * 
+     * @author David M. Carr
+     * @since 0.1.1
+     */
+    @SuppressWarnings("serial")
+    public static class AggregateBuilderException extends RuntimeException {
+        AggregateBuilderException(String message) {
+            super(message);
+        }
+    }
+    
     /**
      * Returns a new AggregateBuilder for the specified collection. All
      * subsequent operators will be treated as part of the processing pipeline.
      * result.
      * 
      * @return the output of running the aggregation pipeline
-     * @throws IllegalStateException if you call this method without initially
-     *          specifying a {@link DBCollection} instance or without providing
-     *          any pipeline operations
+     * @throws AggregateBuilderException if you call this method without
+     *          initially specifying a {@link DBCollection} instance or without
+     *          providing any pipeline operations
      * @since 0.1.1
      */
     public AggregationOutput run() {
         if (_collection == null) {
-            throw new IllegalStateException("run() is only supported if you " +
-                    "initialized the builder with a DBCollection instance.  " +
-                    "Otherwise, use get() instead.");
+            throw new AggregateBuilderException("run() is only supported if " +
+                    "you initialized the builder with a DBCollection " +
+                    "instance.  Otherwise, use get() instead.");
         }
         if (_pipeline.isEmpty()) {
-            throw new IllegalStateException(
+            throw new AggregateBuilderException(
                     "run() requires a non-empty pipeline");
         }
         DBObject firstOp = (DBObject) _pipeline.get(0);