title: Phalcon - Module exception if does not exist
body: <p>I have set the Route:</p>
  
  <pre><code>$router-&gt;add('/:module/:controller/:action/:params', [
        'module' =&gt; 1,
        'controller' =&gt; 2,
        'action' =&gt; 3,
        'params' =&gt; 4
  ]);
  </code></pre>
  
  <p>When I enter URL to the browser, for example: auth/login/index and module under this URL does not exist, so it throws an exception:</p>
  
  <pre><code>Phalcon\Mvc\Application\Exception: Module 'auth' isn't registered in the application container
  </code></pre>
  
  <p>How can I catch this exception?</p>
  
  <p><strong>SOLUTION</strong>:</p>
  
  <pre><code>    $router-&gt;add('/:module/:controller/:action/:params', [
          'module' =&gt; 1,
          'controller' =&gt; 2,
          'action' =&gt; 3,
          'params' =&gt; 4
      ])-&gt;beforeMatch(function($uri) use ($application) {
  
          $modules = $application-&gt;getModules();
  
          $moduleName = array_filter(explode('/', $uri))[1];
  
          if(!isset($modules[$moduleName]))
              return false;
  
          return true;
      });
  </code></pre>
  
  <p>In beforeMatch method I check If module exist.</p>