title: How to throw an exception in your Extension?
body: <p>In an Extbase extension, the need may arise to inform the user about an error or exception.</p>
  <p>In my case, I have to parse some data from a potentially bad source. So the extension has to validate this data. And if the data is invalid, it needs to throw an exception that then can be handled by TYPO3.</p>
  <p>However, I can only find information about how the exception and error handlers works, but no information on how to correctly throw an exception from inside an extension.</p>
  <p>So what is the intended way to throw an exception from inside an Extbase extension?</p>
  <h2>Expected result</h2>
  <p>If I produce a syntax error, TYPO3 displays a message similar to this:
  <a href="https://i.stack.imgur.com/OcZB3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OcZB3.png" alt="enter image description here" /></a>
  (Taken from <a href="https://docs.typo3.org/typo3cms/CoreApiReference/ErrorAndExceptionHandling/Screenshots/Index.html" rel="nofollow noreferrer">the core API reference</a>.)</p>
  <p>That is what I would expect a <em>correctly</em> thrown error or exception to look like.</p>
  <h2>What I tried</h2>
  <p>Edit: I tried throwing an error like this:</p>
  <pre><code>throw new \Exception('Invalid data');
  </code></pre>
  <p>However, all the frontend displays is</p>
  <blockquote>
  <p>Oops, an error occurred! Code: 20160721101726b5339896</p>
  </blockquote>
  <p>Another possible way to produce an error:</p>
  <pre><code>$GLOBALS['TSFE']-&gt;pageNotFoundAndExit('Invalid data');
  </code></pre>
  <p>However, this shows a Page Not Found error instead of the expected exception.</p>