Simplify exception handling.

This commit is contained in:
Bastian Kleineidam 2013-03-08 00:06:50 +01:00
parent 1d7410c038
commit 2bdf0d588d
2 changed files with 4 additions and 7 deletions

6
dosage
View file

@ -129,7 +129,7 @@ def displayHelp(comics):
try: try:
for scraperobj in getScrapers(comics): for scraperobj in getScrapers(comics):
displayComicHelp(scraperobj) displayComicHelp(scraperobj)
except ValueError as msg: except Exception as msg:
out.error(msg) out.error(msg)
return 1 return 1
return 0 return 0
@ -157,7 +157,7 @@ def getComics(options):
try: try:
for scraperobj in getScrapers(options.comic, options.basepath, options.adult, options.multimatch): for scraperobj in getScrapers(options.comic, options.basepath, options.adult, options.multimatch):
errors += getStrips(scraperobj, options) errors += getStrips(scraperobj, options)
except ValueError as msg: except Exception as msg:
out.error(msg) out.error(msg)
errors += 1 errors += 1
finally: finally:
@ -185,7 +185,7 @@ def getStrips(scraperobj, options):
# stop when retrieval skipped an image for one comic strip # stop when retrieval skipped an image for one comic strip
out.info("Stop retrieval because image file already exists") out.info("Stop retrieval because image file already exists")
break break
except (ValueError, IOError) as msg: except Exception as msg:
out.error(msg) out.error(msg)
errors += 1 errors += 1
return errors return errors

View file

@ -49,10 +49,7 @@ class ComicImage(object):
def connect(self): def connect(self):
"""Connect to host and get meta information.""" """Connect to host and get meta information."""
try: self.urlobj = getImageObject(self.url, self.referrer, self.session)
self.urlobj = getImageObject(self.url, self.referrer, self.session)
except IOError as msg:
raise IOError('error retrieving URL %s: %s' % (self.url, msg))
content_type = unquote(self.urlobj.headers.get('content-type', 'application/octet-stream')) content_type = unquote(self.urlobj.headers.get('content-type', 'application/octet-stream'))
content_type = content_type.split(';', 1)[0] content_type = content_type.split(';', 1)[0]
if '/' in content_type: if '/' in content_type: