0

Let's say I have code:

try:
    os.listdir('/sdcdsc')
except:
    print 'Error'

From Python-way point of view (or anything else) - is there something wrong/bad using such except *?

It's impossible to do except ExeptionName as error in this way - but this code works.

kame
  • 20,848
  • 33
  • 104
  • 159
setevoy
  • 4,374
  • 11
  • 50
  • 87
  • It would seem like the try/except would be completely unnecessary if you do that. If it is an error, python will display it. – Pax Vobiscum Apr 15 '16 at 12:43
  • See also Google Python Style Guide [Exceptions section](https://google.github.io/styleguide/pyguide.html?showone=Exceptions#Exceptions). – Xiflado Apr 15 '16 at 12:45
  • Unless you want the code to just run, regardless of any errors. Then it may be useful. – flyingmeatball Apr 15 '16 at 12:51
  • the question is: what do you want to do after catching the exception? If u want to only print the string `Error`, u can raise the Exception after printing with `raise`? `except *` isn't bad. It's only bad, if you ignore the exception – qvpham Apr 15 '16 at 13:01

0 Answers0