i have function geocodes address. don't want function die trying catch error , return tuple instead. want differentiate between errors, use try/except in multiple places. is there such thing many try/except? how optimize function? here code: def geocode(address): js = '' try: urlq = urllib.urlencode({'address':address, 'sensor':'false'}) except exception, e: return (false, "error url-encoding address. error:%s" % e, js, 'failed') try: f = urllib2.urlopen(geo_url + urlq) d = f.read() except exception, e: return (false, "error making connection. error:%s" % e, js, 'failed') # try: js = json.loads(d) except exception, e: return (false, "error converting json. error:%s" % e, js, 'failed') return (true, '', js, 'ok') catching exception bad idea. want specify error want catch. ...
Comments
Post a Comment