Change exit calls to throwing an exception

This way the error won't be fatal in a unit test
DRY use OC_Template::printErrorPage
In debug mode uncaught exceptions should display a nice page
Only display call trace in debug mode
Fixed review issues
Merge pull request #4150 from owncloud/better-error-handling

Better error handling