title: Laravel 4: Create a default route
body: <p>I'm trying to create a default route in my Laravel 4 REST API, that hits, when none of my other defined routes matches the request, to return a specific error to the caller.</p>
  
  <p>Is this possible? Unfortunately, I found nothing in the docs, so I played around and tried using a wildcard (<code>*</code>) as the last Route definition in my <code>routes.php</code> but that doesn't work.</p>
  
  <pre><code>Route::when("*", function(){
      throw new CustomizedException('Route not found...');
  });
  </code></pre>
  
  <p>When I have this route and do an <code>artisan routes</code>, I get an Exception:
  <code>{"error":{"type":"ErrorException","message":"Object of class Closure could not be converted to string","file":"\/Applications\/MAMP\/htdocs\/CampaigningTools\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Console\/RoutesCommand.php","line":153}}</code></p>
  
  <p>Calling an inexistent route does not trigger my customized Exception, but the standard one:
  <code>{"error":{"type":"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException","message":"","file":"\/Applications\/MAMP\/htdocs\/CampaigningTools\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php","line":1429}}</code></p>
  
  <p>I also tried using <code>any</code> as suggested <a href="https://stackoverflow.com/a/13297541/320564">in this post</a>, but that also doesn't work:</p>
  
  <pre><code>Route::any( '(.*)', function( $page ){
      throw new ValidationException('Custom error');
  });
  </code></pre>
  
  <p>This route also doesn't fire, when I call an inexistent route.</p>
  
  <p>Any hints, what I'm doing wrong would be appreciated.</p>