diff --git a/lib/app.php b/lib/app.php
index baacf508d8e280ad185c4a7fe9ca3091a225c938..2437896157ae5c272556cfa82c852f84f8d3f356 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -839,9 +839,9 @@ class OC_App{
 					OC_Hook::emit('update', 'success', 'Updated '.$info['name'].' app');
 				}
 				catch (Exception $e) {
-					echo 'Failed to upgrade "'.$app.'". Exception="'.$e->getMessage().'"';
 					OC_Hook::emit('update', 'failure', 'Failed to update '.$info['name'].' app: '.$e->getMessage());
-					die;
+					$l = OC_L10N::get('lib');
+					throw new RuntimeException($l->t('Failed to upgrade "%s".', array($app)), 0, $e);
 				}
 				OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
 			}
diff --git a/lib/base.php b/lib/base.php
index 1ff462819db4b5a1901cff0aeb213be6748f8bda..df57fe979f3e9d8b421ae9fa9d89343b41d2dc36 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -422,9 +422,13 @@ class OC {
 			}
 		}
 
-		if (!defined('PHPUNIT_RUN') and !(defined('DEBUG') and DEBUG)) {
-			OC\Log\ErrorHandler::register();
-			OC\Log\ErrorHandler::setLogger(OC_Log::$object);
+		if (!defined('PHPUNIT_RUN')) {
+			if (defined('DEBUG') and DEBUG) {
+				set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
+			} else {
+				OC\Log\ErrorHandler::register();
+				OC\Log\ErrorHandler::setLogger(OC_Log::$object);
+			}
 		}
 
 		// register the stream wrappers
diff --git a/lib/files.php b/lib/files.php
index f5dffd970d2ca13b817cd96c5c3a65c63dd3a9ab..c705d2adb1a20f7c0dcbc09871792a0b9a093b6f 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -62,7 +62,8 @@ class OC_Files {
 			$zip = new ZipArchive();
 			$filename = OC_Helper::tmpFile('.zip');
 			if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) {
-				exit("cannot open <$filename>\n");
+				$l = OC_L10N::get('lib');
+				throw new Exception($l->t('cannot open "%s"', array($filename)));
 			}
 			foreach ($files as $file) {
 				$file = $dir . '/' . $file;
@@ -93,7 +94,8 @@ class OC_Files {
 			$zip = new ZipArchive();
 			$filename = OC_Helper::tmpFile('.zip');
 			if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) {
-				exit("cannot open <$filename>\n");
+				$l = OC_L10N::get('lib');
+				throw new Exception($l->t('cannot open "%s"', array($filename)));
 			}
 			$file = $dir . '/' . $files;
 			self::zipAddDir($file, $zip);
@@ -220,16 +222,11 @@ class OC_Files {
 		if (!OC_Config::getValue('allowZipDownload', true)) {
 			$l = OC_L10N::get('lib');
 			header("HTTP/1.0 409 Conflict");
-			$tmpl = new OC_Template('', 'error', 'user');
-			$errors = array(
-				array(
-					'error' => $l->t('ZIP download is turned off.'),
-					'hint' => $l->t('Files need to be downloaded one by one.')
-						. '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>',
-				)
+			OC_Template::printErrorPage(
+					$l->t('ZIP download is turned off.'),
+					$l->t('Files need to be downloaded one by one.')
+						. '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>'
 			);
-			$tmpl->assign('errors', $errors);
-			$tmpl->printPage();
 			exit;
 		}
 
@@ -252,17 +249,12 @@ class OC_Files {
 			if ($totalsize > $zipLimit) {
 				$l = OC_L10N::get('lib');
 				header("HTTP/1.0 409 Conflict");
-				$tmpl = new OC_Template('', 'error', 'user');
-				$errors = array(
-					array(
-						'error' => $l->t('Selected files too large to generate zip file.'),
-						'hint' => 'Download the files in smaller chunks, seperately'
-							.' or kindly ask your administrator.<br/><a href="javascript:history.back()">'
-							. $l->t('Back to Files') . '</a>',
-					)
+				OC_Template::printErrorPage(
+						$l->t('Selected files too large to generate zip file.'),
+						$l->t('Download the files in smaller chunks, seperately or kindly ask your administrator.')
+						.'<br/><a href="javascript:history.back()">'
+						. $l->t('Back to Files') . '</a>'
 				);
-				$tmpl->assign('errors', $errors);
-				$tmpl->printPage();
 				exit;
 			}
 		}
diff --git a/lib/helper.php b/lib/helper.php
index df0d120976df44e9ef9bff1e701d9efeb9f123cb..ca508e1d9334dd5ad85a308babbd5977ab5b9253 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -176,8 +176,7 @@ class OC_Helper {
 		}elseif( file_exists( OC::$SERVERROOT."/core/img/$image" )) {
 			return OC::$WEBROOT."/core/img/$image";
 		}else{
-			echo('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
-			die();
+			throw new RuntimeException('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
 		}
 	}
 
diff --git a/lib/setup.php b/lib/setup.php
index 59f4cab75debfafffa3a956b3fa7151887f4d2f1..05a49890976f6d5d9b0d4855218081f6922aadc4 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -185,9 +185,7 @@ class OC_Setup {
 			$hint = $l->t('Please double check the <a href=\'%s\'>installation guides</a>.',
 				'http://doc.owncloud.org/server/5.0/admin_manual/installation.html');
 
-			$tmpl = new OC_Template('', 'error', 'guest');
-			$tmpl->assign('errors', array(1 => array('error' => $error, 'hint' => $hint)));
-			$tmpl->printPage();
+			OC_Template::printErrorPage($error, $hint);
 			exit();
 		}
 	}
diff --git a/lib/template.php b/lib/template.php
index d48e3b36821c4ea67b7f83eff37b5f0a342df288..339b30eb414cd0d83584825ee4e7d0d831165946 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -531,17 +531,25 @@ class OC_Template{
 		if ($exception->getCode()) {
 			$error_msg = '['.$exception->getCode().'] '.$error_msg;
 		}
-		$hint = $exception->getTraceAsString();
-		if (!empty($hint)) {
-			$hint = '<pre>'.$hint.'</pre>';
-		}
-		while (method_exists($exception,'previous') && $exception = $exception->previous()) {
-			$error_msg .= '<br/>Caused by: ';
-			if ($exception->getCode()) {
-				$error_msg .= '['.$exception->getCode().'] ';
+		if (defined('DEBUG') and DEBUG) {
+			$hint = $exception->getTraceAsString();
+			if (!empty($hint)) {
+				$hint = '<pre>'.$hint.'</pre>';
+			}
+			$l = OC_L10N::get('lib');
+			while (method_exists($exception, 'previous') && $exception = $exception->previous()) {
+				$error_msg .= '<br/>'.$l->t('Caused by:').' ';
+				if ($exception->getCode()) {
+					$error_msg .= '['.$exception->getCode().'] ';
+				}
+				$error_msg .= $exception->getMessage();
+			};
+		} else {
+			$hint = '';
+			if ($exception instanceof \OC\HintException) {
+				$hint = $exception->getHint();
 			}
-			$error_msg .= $exception->getMessage();
-		};
+		}
 		self::printErrorPage($error_msg, $hint);
 	}
 }