title: __toString() must not throw an exception
body: <p>when i go to the browser at index.php, i get the following error
  <code>Fatal error: Method MyDirectoryIterator::__toString() must not throw an exception in /home/oussama/Desktop/CoursesTraining/OOPInPHP/index.php on line 0</code></p>
  
  <p>when i try to catch the exception, i get the same error, so how am i supposed
  to know what the exception is?</p>
  
  <p>my home directory contains two files index.php and MyDirectoryIterator.inc.php, 
  am using composer to handle autoload, and this is the source content:</p>
  
  <p>index.php</p>
  
  <pre><code>&lt;?php
  
  require_once './vendor/autoload.php';
  
  
  $files = new MyDirectoryIterator('../');
  echo $files;
  </code></pre>
  
  <p>MyDirectoryIterator.inc.php</p>
  
  <pre><code>&lt;?php
  
  
  class MyDirectoryIterator {
  
      protected $_path;
      protected $_files;
      protected $_rfiles;
  
      function __construct($path)
      {
          $this-&gt;_path = __DIR__ . '/' . $path;
          $this-&gt;_files = new RecursiveDirectoryIterator($path);
          $this-&gt;_files-&gt;setFlags(
              FileSystemIterator::UNIX_PATHS |
              FileSystemIterator::SKIP_DOTS
          );
  
          $this-&gt;_rfiles = new RecursiveIteratorIterator($this-&gt;_files);
      }
  
      function __toString()
      {
          $output = '';
  
          foreach($this-&gt;_rfiles as $file)
          {
              $output .= $file . '&lt;br /&gt;';
          }
  
          return $output;
      }
  }
  </code></pre>
  
  <p>when i copy the content of __toString, to __construct, the code behave as expected.
  so why i get that error, when i execute <code>echo $files</code> from my index.php?</p>
  
  <p>any ideas.</p>