diff --git a/kwant/graph/core.pyx b/kwant/graph/core.pyx
index d991fa745ea34858d08d46881d8a285e222749b5..425e4f221e066a917f55461048842da5e47dead4 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