From 6934eb31f47694ee5296013fabd00cb73c2bd187 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 25 Aug 2012 09:16:38 -0400 Subject: [PATCH] Create an appropriate exception type. --- irker.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/irker.py b/irker.py index af08568..7219e30 100755 --- 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) -- 2.26.2