diff --git a/repos/base/include/base/native_capability.h b/repos/base/include/base/native_capability.h
index 5e02a15e8b..6170764734 100644
--- a/repos/base/include/base/native_capability.h
+++ b/repos/base/include/base/native_capability.h
@@ -16,6 +16,7 @@
#include
#include
+#include
namespace Genode { class Native_capability; }
@@ -24,6 +25,8 @@ class Genode::Native_capability
{
public:
+ struct Reference_count_overflow : Exception { };
+
/*
* Platform-specific raw information of the capability that is
* transferred as-is when the capability is delegated.
diff --git a/repos/base/src/include/base/internal/capability_space_tpl.h b/repos/base/src/include/base/internal/capability_space_tpl.h
index 0a50e49bfa..9a465c37a2 100644
--- a/repos/base/src/include/base/internal/capability_space_tpl.h
+++ b/repos/base/src/include/base/internal/capability_space_tpl.h
@@ -176,7 +176,7 @@ class Genode::Capability_space_tpl
Lock::Guard guard(_lock);
if (data.inc_ref() == 255)
- error("cap ref count overflow");
+ throw Native_capability::Reference_count_overflow();
}
Rpc_obj_key rpc_obj_key(Data const &data) const