Skip to main content

I am using aI'm writing code which havethat has to deal with a lot of IndexError exceptionexceptions.
So, I took the idea of putting exception handler in the following wayused a try except block:

try:
    <do some level_1 calculations>
except IndexError:
    <change to level_2 calculations>  

But, what if my exception-handler again raises another IndexError  ?
How can I be able tosafely put another IndexError exception with this code-structure ?
So structure so that, if the level_2 calculation again gotgets caught in an IndexError, then the code runs "level_3 calculations" as anan exception again and so on.

I am using a code which have to deal with a lot of IndexError exception.
So, I took the idea of putting exception handler in the following way:

try:
    <do some level_1 calculations>
except IndexError:
    <change to level_2 calculations>  

But, what if my exception-handler again raises another IndexError  ?
How can I be able to put another IndexError exception with this code-structure ?
So that, if the level_2 calculation again got in an IndexError, then the code runs "level_3 calculations" as an exception again and so on.

I'm writing code that has to deal with a lot of IndexError exceptions.
So, I used a try except block:

try:
    <do some level_1 calculations>
except IndexError:
    <change to level_2 calculations>  

But, what if my exception-handler again raises another IndexError?
How can I safely put another IndexError exception with this code structure so that, if the level_2 calculation again gets caught in an IndexError, then the code runs "level_3 calculations" as an exception again and so on.

Source Link
diffracteD
  • 758
  • 3
  • 11
  • 32

multiple exception handler in python

I am using a code which have to deal with a lot of IndexError exception.
So, I took the idea of putting exception handler in the following way:

try:
    <do some level_1 calculations>
except IndexError:
    <change to level_2 calculations>  

But, what if my exception-handler again raises another IndexError ?
How can I be able to put another IndexError exception with this code-structure ?
So that, if the level_2 calculation again got in an IndexError, then the code runs "level_3 calculations" as an exception again and so on.