diff --git a/emper/Common.cpp b/emper/Common.cpp
index 0f94fab5f59f4acceb3f9649759179bc471a669e..fadfeb291e59a4455b6ec6301f492dcf286d6758 100644
--- a/emper/Common.cpp
+++ b/emper/Common.cpp
@@ -1,10 +1,15 @@
 #include <stdio.h>
 #include <cstdlib>
 #include <iostream>
+#include <cstdio>
 
 #include "Common.hpp"
 
-void die(const char* message) {
-	std::cout << message << std::endl;
+void die(const char* message, bool usePerror) {
+	if (usePerror) {
+		std::perror(message);
+	} else {
+		std::cout << message << std::endl;
+	}
 	exit(EXIT_FAILURE);
 }
diff --git a/emper/Common.hpp b/emper/Common.hpp
index 29fcfac91c3e768693bdfda1430805e8829f3cc7..a93a8017f246fd27382d34deed789c0123d59d1f 100644
--- a/emper/Common.hpp
+++ b/emper/Common.hpp
@@ -8,14 +8,15 @@ typedef std::function<void(void)> func_t;
 
 #define STRINGIFY(x) #x
 #define TOSTRING(x) STRINGIFY(x)
-#define DIE die(__FILE__ ":" TOSTRING(__LINE__))
-#define DIE_MSG(x) die(__FILE__ ":" TOSTRING(__LINE__) "-" #x)
+#define DIE die(__FILE__ ":" TOSTRING(__LINE__), false)
+#define DIE_MSG(x) die(__FILE__ ":" TOSTRING(__LINE__) "-" #x, false)
+#define DIE_MSG_ERRNO(x) die(__FILE__ ":" TOSTRING(__LINE__) "-" #x, true)
 
 #define likely(x)       __builtin_expect(!!(x),1)
 #define unlikely(x)     __builtin_expect(!!(x),0)
 
 #define ALIGN_TO_CACHE_LINE alignas(64)
 
-void die(const char* message);
+void die(const char* message, bool usePerror);
 
 typedef unsigned int WORD;
diff --git a/emper/Runtime.cpp b/emper/Runtime.cpp
index 7692c9282d9060d19100cba957d0fa40be33a52a..3f942ee6cd85f0f3281f87c6f0d23a5b82e0679e 100644
--- a/emper/Runtime.cpp
+++ b/emper/Runtime.cpp
@@ -52,7 +52,7 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategy& strategy) : workerCoun
 		CPU_SET(i % nprocs, &cpuset);
 
 		errno = pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset);
-		if (errno) DIE_MSG("pthread_attr_setaffinity_np() failed");
+		if (errno) DIE_MSG_ERRNO("pthread_attr_setaffinity_np() failed");
 		// End non portable.
 
 		// Load the worker ID into the worker ID map.
@@ -60,16 +60,16 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategy& strategy) : workerCoun
 
 		auto thread_function =  [](void* voidWorkerId) -> void* { return currentRuntime->workerLoop(voidWorkerId); };
 		errno = pthread_create(&threads[i], &attr, thread_function, &workerIds[i]);
-		if (errno) DIE_MSG("pthread_create() failed");
+		if (errno) DIE_MSG_ERRNO("pthread_create() failed");
 	}
 }
 
 Runtime::~Runtime() {
 	DBG("Runtime " << this << " is terminating");
 	for (workerid_t i = 0; i < workerCount; ++i) {
-		int res = pthread_cancel(threads[i]);
-		if (res) {
-			DIE_MSG("pthread_cancel() failed");
+		errno = pthread_cancel(threads[i]);
+		if (errno) {
+			DIE_MSG_ERRNO("pthread_cancel() failed");
 		}
 	}
 	{
@@ -84,9 +84,9 @@ void* Runtime::workerLoop(void* voidWorkerId) {
 	LOGD("Worker loop started by thread " << syscall(SYS_gettid));
 
 	int oldType;
-	int res = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldType);
-	if (res) {
-		DIE_MSG("pthread_setcanceltype() failed");
+	errno = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldType);
+	if (errno) {
+		DIE_MSG_ERRNO("pthread_setcanceltype() failed");
 	}
 
 	// Initialze the workers PRNG seed.