Create an appropriate exception type.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 25 Aug 2012 13:16:38 +0000 (09:16 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 25 Aug 2012 13:16:38 +0000 (09:16 -0400)
irker.py

index af0856846c57223f92b417c63ad0b021e3418625..7219e304c9d61c920e847f1e4bb41fe2c9e87f2c 100755 (executable)
--- a/irker.py
+++ b/irker.py
@@ -8,9 +8,14 @@ and relays to IRC channels.
 Requires Python 2.6.
 
 """
-import os, sys, json, irclib, getopt
+import os, sys, json, irclib, exceptions, getopt
 import threading, Queue
 
+class SessionException(exceptions.Exception):
+    def __init__(self, message):
+        exceptions.Exception.__init__(self)
+        self.message = message
+
 class Session():
     "IRC session and message queue processing."
     def __init__(self, url):
@@ -22,12 +27,15 @@ class Session():
         self.thread.start()
         # The channel specification
         if not url.startswith("irc://") or url.count("/") != 3:
-            raise ValueError
+            raise SessionException("ill-formed IRC URL")
         else:
             url = url[6:]
         parts = url.split(":", 1)
         if len(parts) == 2:
-            self.port = int(parts[1])
+            try:
+                self.port = int(parts[1])
+            except ValuError:
+                raise SessionException("invalid port number")
         else:
             self.port = 6667
         (self.server, self.channel) = parts[0].split("/", 1)