ColdFusion: selectively handling missing methods

If you invoke a method on a ColdFusion object (aka CFC) that doesn’t exist, you get a handy exception telling you so, as you’d expect.

If, however, you implement the onMissingMethod method in your CFC (see the cfcomponent doc page, right down the bottom), all invocations of non-existent methods will be routed to it. You will never see another missing method exception for that object.

That’s fine and dandy, but what if you only want to handle specific method names, and have all others throw the missing method exception?

The short answer is that you’re on your own. Specifically:

  1. There is no equivalent of rethrow (remissing?)
  2. There is no way to manually recreate exactly the same exception and stack trace that the default missing method handler would give you.

So, if you don’t want to handle a method name, you can either throw an error of your choice, or fail silently.

BTW, I don’t think #2 is a big deal. I mention this only because what little discussion exists on this topic tends to suggest throwing the “same exception” that the ColdFusion engine does, and as far as I know that’s hard to impossible.

Leave a Reply

Your email address will not be published. Required fields are marked *