diff --git a/kwant/graph/core.pyx b/kwant/graph/core.pyx
index 2ef377be901662cf5afd31b248333757e18dc606..eca0c49d6be073cd7bf64fda75bf4fb6302c94bf 100644
--- a/kwant/graph/core.pyx
+++ b/kwant/graph/core.pyx
@@ -72,7 +72,7 @@ cdef class Graph:
             raise MemoryError
         self.capacity = capacity
 
-    cpdef gint add_edge(self, gint tail, gint head):
+    cpdef gint add_edge(self, gint tail, gint head) except -1:
         """Add the directed edge (`tail`, `head`) to the graph.
 
         Parameters