Throwing exceptions in PHP7 for validation?
<p>I'm updating a framework I finished a while ago. I got some feedback from the community, and decided to build a little portable MVC framework to house my packages. </p>

<p>I'm currently working on the router, and it's working perfectly when I feed the framework the URL it's supposed to get. I used <code>throw new Exception("MyMessage")</code> to make validating the URLs more object oriented and a lot simpler. </p>

<p>However, this is the first time I've ever attempted this, and it seems that my catch block is not catching the errors. </p>

<p>Specifically, whenever there is an error thrown in the <code>try</code> block, I want it to trigger my some code in the <code>catch</code> block. 
Here is the full <code>try/catch</code> block...</p>

<pre><code>try
      {
        if (isset($url[0]) &amp;&amp; isset($url[1]) &amp;&amp; isset($url[2]) &amp;&amp; $url[0] . $url[1] . $url[2] != "")
        {
          //Figure out if we're handling a package, or working in the package manager.
          if ($url[0] != "ignition" &amp;&amp; $url[0] != "")
          {
            if (!file_exists("../packages/" . $url[0]))
            {
              throw new Exception($manager_error = "Package \"" . $url[0] . "\" not found.");
            }
            else
            {
              $this-&gt;package = $url[0];
              $this-&gt;path = "../packages/$this-&gt;package/controllers/";
            }
            unset($url[0]);
          }
          elseif ($url[0] == "")
            throw new Exception("No package name provided.");
          //Check if controller exists.
          if ($url[1] != "")
          {
            //Check if controller file exists.
            if (file_exists($this-&gt;path . $url[1] . ".php"))
            {
              $this-&gt;controller = $url[1];
              require_once($this-&gt;path . "$this-&gt;controller.php");
              unset($url[1]);
              //Check that controller exists in file.
              if (class_exists($this-&gt;controller))
              {
                $this-&gt;controller = new $this-&gt;controller;
                //Check that method exists in controller.
                if ($url[2] != "")
                {
                  if (method_exists($this-&gt;controller, $url[2]))
                  {
                    $this-&gt;method = $url[2];
                    unset($url[2]);
                    if (!empty($url))
                      $this-&gt;params = array_values($url);
                  }
                  else
                    throw new Exception("Method \"" . $url[2] . "\" not found in controller \"" . get_class($this-&gt;controller) . "\".");
                }
                else
                  throw new Exception("No method name provided.");
              }
              else
                throw new Exception("Controller \"$this-&gt;controller\" not contained in it's file.");
            } else {
              throw new Exception("Controller file \"" . $url[1] . ".php\" not found.");
            }
          }
          else
            throw new Exception("No controller name provided.");
        }
        else
        {
          //Check if we have one or more arguments, but less than the three
          //we need for a complete route.
          if (!isset($url[0]))
            $url[0] = "";
          if (!isset($url[1]))
            $url[1] = "";
          if (!isset($url[2]))
            $url[2] = "";
          if ($url[0] . $url[1] . $url[2] != "") {
            if ($url[0] == "")
              throw new Exception("No package name provided.");
            elseif ($url[1] == "")
              throw new Exception("No controller name provided.");
            elseif ($url[2] = "")
              throw new Exception("No method name provided.");
          }
        }
      }
      catch (Exception $e)
      {
        unset($url);
        $this-&gt;manager_error = $e-&gt;getMessage();
        $this-&gt;package = "ignition";
        $this-&gt;controller = "ignition";
        $this-&gt;method = "notFound";
        $this-&gt;path = "../package_manager/controllers/";
        $this-&gt;params[] = $this-&gt;manager_error;
        require_once($this-&gt;path . "$this-&gt;controller.php");
        $this-&gt;controller = new $this-&gt;controller;
      }
</code></pre>

<p>I've tried making a very simple version where I just echoed out some text and put some wrong URLs in the address bar to try and get SOMETHING from the catch block, but I haven't been successful. </p>

<p>I also would like to mention that this is in the constructor function of a class, if that makes any kind of difference. </p>

<p>What am I doing wrong here, and how can I change this script to get the exceptions to catch?</p>