diff --git a/src/io_commands.c b/src/io_commands.c
index 9a30d23a66aaf735b77ca9bddc34730f41fc7bee..4641922be9181ce513ef1a7667ab944097c37e80 100644
--- a/src/io_commands.c
+++ b/src/io_commands.c
@@ -373,13 +373,20 @@ DEFINE_COMMAND(connect_local_command)
       struct exception_handler *e UNUSED)
 {
   CAST(local_info, info, a);
-
-  io_connect_local(info,
-		   make_connect_continuation(NULL, c),
-		   e);
+  
+  static struct exception gateway_exception =
+    STATIC_EXCEPTION(EXC_IO_CONNECT, "no usable gateway socket found");
+  
+  struct lsh_fd *fd = io_connect_local(info,
+				       make_connect_continuation(NULL, c),
+				       e);
+  
+  if (!fd)
+    EXCEPTION_RAISE(e, &gateway_exception);
 }
 
 
+
 /* Takes a listen_value as argument, logs the peer address, and
  * returns the fd object. */