Replace trigger_error With Exceptions For Easier Recovery

In PHP it's not easy to recover from `trigger_error`, especially locally. I've noticed that it would be beneficial to allow the user to catch certain errors, for example when a template file is not found - to show a default page.

In general, I believe that Exceptions are much cleaner in PHP than `trigger_error`. I have decided to use the generic `ErrorException` class here, as it is built-in and denotes a fatal error like `trigger_error`, but is catchable. And it avoid defining our own `Exception` class.

However, the function `template` throws two different exceptions but with the same exception class. We should think of a solution for this, preferably without having to declare our own classes.

For some reason it also added my change to allow different template file endings in `template`.