Re: Catching an unknown error

2007-03-23 Thread skip
Harlin> value = raw_input("Type a divisor: ") Harlin> try: Harlin>value = int(value) Harlin>print "42 / %d = %d" % (value, 42/value) Harlin> except ValueError: Harlin> print "I can't convert the value to an integer" Harlin> except ZeroDivisionError: Harl

Re: Catching an unknown error

2007-03-23 Thread Harlin Seritt
On Mar 23, 9:42 am, [EMAIL PROTECTED] wrote: > On Mar 23, 8:16 am, "Harlin Seritt" <[EMAIL PROTECTED]> wrote: > > > > > Using the code below: > > > ---BEGIN CODE--- > > > value = raw_input("Type a divisor: ") > > try: > >value = int(value) > >print "42 / %d = %d" % (value, 42/value) > > exc

Re: Catching an unknown error

2007-03-23 Thread kyosohma
On Mar 23, 8:16 am, "Harlin Seritt" <[EMAIL PROTECTED]> wrote: > Using the code below: > > ---BEGIN CODE--- > > value = raw_input("Type a divisor: ") > try: >value = int(value) >print "42 / %d = %d" % (value, 42/value) > except ValueError: > print "I can't convert the value to an in

Re: Catching an unknown error

2007-03-23 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Make the last 'except' block like this: > > Except Exception, e: > print e while that's good enough for the given example, it's not good enough for the general case (in contemporary Python, exceptions don't have to inherit from the Exception class). -- http://m

Re: Catching an unknown error

2007-03-23 Thread kyosohma
On Mar 23, 8:29 am, [EMAIL PROTECTED] wrote: > On Mar 23, 8:16 am, "Harlin Seritt" <[EMAIL PROTECTED]> wrote: > > > > > Using the code below: > > > ---BEGIN CODE--- > > > value = raw_input("Type a divisor: ") > > try: > >value = int(value) > >print "42 / %d = %d" % (value, 42/value) > > exc

Re: Catching an unknown error

2007-03-23 Thread Fredrik Lundh
Harlin Seritt wrote: > In the last 'except' block, how can I print out the particular error > name even though one is not specifically named? the sys.exc_info() function returns information about the current exception. see: http://effbot.org/pyref/sys.exc_info -- http://mail.python.or

Re: Catching an unknown error

2007-03-23 Thread kyosohma
On Mar 23, 8:16 am, "Harlin Seritt" <[EMAIL PROTECTED]> wrote: > Using the code below: > > ---BEGIN CODE--- > > value = raw_input("Type a divisor: ") > try: >value = int(value) >print "42 / %d = %d" % (value, 42/value) > except ValueError: > print "I can't convert the value to an in

Catching an unknown error

2007-03-23 Thread Harlin Seritt
Using the code below: ---BEGIN CODE--- value = raw_input("Type a divisor: ") try: value = int(value) print "42 / %d = %d" % (value, 42/value) except ValueError: print "I can't convert the value to an integer" except ZeroDivisionError: print "Your value should not be zero" ex