       end
 
     quote do
-      opts     = Keyword.put(unquote(options), :singular, true)
-      resource = Resource.build(unquote(path), unquote(controller), opts)
-
-      path = resource.path
-      ctrl = resource.controller
-      opts = resource.route
-
-      Enum.each resource.actions, fn action ->
-        case action do
-          :show    -> get    path,            ctrl, :show, opts
-          :new     -> get    path <> "/new",  ctrl, :new, opts
-          :edit    -> get    path <> "/edit", ctrl, :edit, opts
-          :create  -> post   path,            ctrl, :create, opts
-          :delete  -> delete path,            ctrl, :delete, opts
-          :update  ->
-            patch path, ctrl, :update, opts
-            put   path, ctrl, :update, Keyword.put(opts, :as, nil)
-        end
-      end
-
-      unquote(scope)
+      try do
+        opts     = Keyword.put(unquote(options), :singular, true)
+        resource = Resource.build(unquote(path), unquote(controller), opts)
+
+        path = resource.path
+        ctrl = resource.controller
+        opts = resource.route
+
+        Enum.each resource.actions, fn action ->
+          case action do
+            :show    -> get    path,            ctrl, :show, opts
+            :new     -> get    path <> "/new",  ctrl, :new, opts
+            :edit    -> get    path <> "/edit", ctrl, :edit, opts
+            :create  -> post   path,            ctrl, :create, opts
+            :delete  -> delete path,            ctrl, :delete, opts
+            :update  ->
+              patch path, ctrl, :update, opts
+              put   path, ctrl, :update, Keyword.put(opts, :as, nil)
+          end
+        end
+
+        unquote(scope)
+      after
+        :ok
+      end
     end
   end
 

  end

  defp add_route(verb, path, controller, action, options) do
    quote bind_quoted: binding() do
      route = Scope.route(__MODULE__, verb, path, controller, action, options)
      exprs = Route.exprs(route)

      @phoenix_routes {route, exprs}

      defp match(var!(conn), unquote(route.verb), unquote(exprs.path), unquote(exprs.host)) do
        unquote(exprs.dispatch)
      end
    end
  end

      end

    quote do
      try do
        resource = Resource.build(unquote(path), unquote(controller), unquote(options))

        parm = resource.param
        path = resource.path
        ctrl = resource.controller
        opts = resource.route

        Enum.each resource.actions, fn action ->
          case action do
            :index   -> get    path,                            ctrl, :index, opts
            :show    -> get    path <> "/:" <> parm,            ctrl, :show, opts
            :new     -> get    path <> "/new",                  ctrl, :new, opts
            :edit    -> get    path <> "/:" <> parm <> "/edit", ctrl, :edit, opts
            :create  -> post   path,                            ctrl, :create, opts
            :delete  -> delete path <> "/:" <> parm,            ctrl, :delete, opts
            :update  ->
              patch path <> "/:" <> parm, ctrl, :update, opts
              put   path <> "/:" <> parm, ctrl, :update, Keyword.put(opts, :as, nil)
          end
        end

        unquote(scope)
      after
        :ok
      end
    end
  end

