$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #94

What is the correct fix?

try:
    run()
except Exception:
    log('general')
except ValueError:
    log('value')
  1. Put except ValueError before Exception
  2. Put except ValueError after the finally
  3. Merge them into one except statement
  4. Change Exception to BaseException
The first matching handler wins, so the broad one makes the specific one unreachable.
Play Problem Solving ▸