About 107,000 results
Open links in new tab
  1. Is it a good practice to use try-except-else in Python?

    Apr 22, 2013 · try: try_this(whatever) except SomeException as the_exception: handle_SomeException(the_exception) # Handle a instance of SomeException or a subclass …

  2. Are nested try/except blocks in Python a good programming …

    Jun 10, 2013 · A good and simple example for nested try/except could be the following: import numpy as np def divide(x, y): try: out = x/y except: try: out = np.inf * x / abs(x) except: out = …

  3. Using 'try' vs. 'if' in Python - Stack Overflow

    So, whereas an if statement always costs you, it's nearly free to set up a try/except block. But when an Exception actually occurs, the cost is much higher. Moral: It's perfectly OK (and …

  4. python - How to properly ignore exceptions - Stack Overflow

    When you just want to do a try/except without handling the exception, how do you do it in Python? Is the following the right way to do it? try : shutil.rmtree ( path ) except : pass For Python 2 …

  5. Using python "with" statement with try-except block

    Sep 4, 2010 · And yes, the way you've combined with and try-except is pretty much the only way to do it, as exceptional errors caused within the open statement itself can't be caught within …

  6. python - One try block with multiple excepts - Stack Overflow

    In Python, is it possible to have multiple except statements for one try statement? Such as: try: #something1 #something2 except ExceptionType1: #return xyz except ExceptionType2: #...

  7. Catch exception and continue try block in Python

    You can achieve what you want, but with a different syntax. You can use a "finally" block after the try/except. Doing this way, python will execute the block of code regardless the exception was …

  8. python - How can I catch multiple exceptions in one line? (in the ...

    This usage, the only form available in Python 2.5 and earlier, is deprecated, and if you wish your code to be forward compatible in Python 3, you should update the syntax to use the new form: …

  9. how to properly use try/except/with inside functions and main

    Sep 21, 2014 · I have the following python pseudo code. I have try/except blocks inside the function that attempts to download the files but if an exception occurred inside the function …

  10. python - Multiple try codes in one block - Stack Overflow

    Jun 26, 2013 · try: code a except ExplicitException: pass try: code b except ExplicitException: pass try: code c except ExplicitException: pass try: code d except ExplicitException: pass I'm …

Refresh