Skip to main content
remove thanks
Source Link
Lesmana
  • 27.4k
  • 12
  • 84
  • 87

Thanks! the question is solved in all the answers given.

Original question follows:

given a traceback error log, i don't always know how to catch a particular exception.

my question is in general, how do i determine which "except" clause to write in order to handle a certain exception.

example 1:

  File "c:\programs\python\lib\httplib.py", line 683, in connect
    raise socket.error, msg
error: (10065, 'No route to host')

example 2:

return codecs.charmap_encode(input,errors,encoding_table)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position(...)

catching the 2nd example is obvious:

try:
    ...
except UnicodeDecodeError:
    ...

how do i catch specifically the first error?

Thanks! the question is solved in all the answers given.

Original question follows:

given a traceback error log, i don't always know how to catch a particular exception.

my question is in general, how do i determine which "except" clause to write in order to handle a certain exception.

example 1:

  File "c:\programs\python\lib\httplib.py", line 683, in connect
    raise socket.error, msg
error: (10065, 'No route to host')

example 2:

return codecs.charmap_encode(input,errors,encoding_table)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position(...)

catching the 2nd example is obvious:

try:
    ...
except UnicodeDecodeError:
    ...

how do i catch specifically the first error?

given a traceback error log, i don't always know how to catch a particular exception.

my question is in general, how do i determine which "except" clause to write in order to handle a certain exception.

example 1:

  File "c:\programs\python\lib\httplib.py", line 683, in connect
    raise socket.error, msg
error: (10065, 'No route to host')

example 2:

return codecs.charmap_encode(input,errors,encoding_table)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position(...)

catching the 2nd example is obvious:

try:
    ...
except UnicodeDecodeError:
    ...

how do i catch specifically the first error?

added 99 characters in body
Source Link
Berry Tsakala
  • 17k
  • 15
  • 66
  • 92

Thanks! the question is solved in all the answers given.

Original question follows:

given a traceback error log, i don't always know how to catch a particular exception.

my question is in general, how do i determine which "except" clause to write in order to handle a certain exception.

example 1:

  File "c:\programs\python\lib\httplib.py", line 683, in connect
    raise socket.error, msg
error: (10065, 'No route to host')

example 2:

return codecs.charmap_encode(input,errors,encoding_table)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position(...)

catching the 2nd example is obvious:

try:
    ...
except UnicodeDecodeError:
    ...

how do i catch specifically the first error?

given a traceback error log, i don't always know how to catch a particular exception.

my question is in general, how do i determine which "except" clause to write in order to handle a certain exception.

example 1:

  File "c:\programs\python\lib\httplib.py", line 683, in connect
    raise socket.error, msg
error: (10065, 'No route to host')

example 2:

return codecs.charmap_encode(input,errors,encoding_table)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position(...)

catching the 2nd example is obvious:

try:
    ...
except UnicodeDecodeError:
    ...

how do i catch specifically the first error?

Thanks! the question is solved in all the answers given.

Original question follows:

given a traceback error log, i don't always know how to catch a particular exception.

my question is in general, how do i determine which "except" clause to write in order to handle a certain exception.

example 1:

  File "c:\programs\python\lib\httplib.py", line 683, in connect
    raise socket.error, msg
error: (10065, 'No route to host')

example 2:

return codecs.charmap_encode(input,errors,encoding_table)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position(...)

catching the 2nd example is obvious:

try:
    ...
except UnicodeDecodeError:
    ...

how do i catch specifically the first error?

Source Link
Berry Tsakala
  • 17k
  • 15
  • 66
  • 92

which exception catches xxxx error in python

given a traceback error log, i don't always know how to catch a particular exception.

my question is in general, how do i determine which "except" clause to write in order to handle a certain exception.

example 1:

  File "c:\programs\python\lib\httplib.py", line 683, in connect
    raise socket.error, msg
error: (10065, 'No route to host')

example 2:

return codecs.charmap_encode(input,errors,encoding_table)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position(...)

catching the 2nd example is obvious:

try:
    ...
except UnicodeDecodeError:
    ...

how do i catch specifically the first error?