diff --git a/tunmgr/tunmgr.py b/tunmgr/tunmgr.py
index 2ae4008c22da90036d63b05f6cfcd142c45b77d6..017f31b00b187746a71fe0c527765bc17b2e0108 100755
--- a/tunmgr/tunmgr.py
+++ b/tunmgr/tunmgr.py
@@ -5,6 +5,7 @@ import selectors
 import socket
 import sys
 import base64
+import traceback
 
 tun = TunTapDevice()
 
@@ -29,12 +30,15 @@ sel.register(s, selectors.EVENT_READ, "sms")
 
 while 1:
     for key, events in sel.select():
-        if key.data=="tun":
-            print("tun")
-            s.sendto(base64.b64encode(tun.read(tun.mtu)), (PEER, PORT))
-        elif key.data == "sms":
-            print("sms")
-            tun.write(base64.b64decode(s.recv(tun.mtu*4))+b"\n")
+        try:
+            if key.data=="tun":
+                print("tun")
+                s.sendto(base64.b64encode(tun.read(tun.mtu)), (PEER, PORT))
+            elif key.data == "sms":
+                print("sms")
+                tun.write(base64.b64decode(s.recv(tun.mtu*4))+b"\n")
+        except Exception:
+            traceback.print_exc()