Is there a way to "unlock" an exception in python?

I have no control over the python library, which is uselessly throwing a specific exception.

Is there a way to handle it using the Except subclass "placebo"? i.e.

class MyException(Exception):
    def __init__(self, value):
        # literally do nothing. return to program flow
        pass
+4
source share
2 answers

raises a certain exception

You have a specific exception, you must handle the exception by specifying the exception class in the except clause of the block try-except.

(.. except Exception...) , Exception ( ), , -, .


:

,

, try-except. .


try-except , -, try-except, .

from somelib import func
from somelib import SomeException


def wrapper_func(*args, **kwargs):
    try:
         func(*args, **kwargs)
    except SomeException:
         pass
+5

, - /-, fuckitpy !

, , , , .

, fuckitpy ( ):

import fuckit
#import some_shitty_module
fuckit('some_shitty_module')
some_shitty_module.some_function()

:

- ? . : , .

import fuckit
fuckit(fuckit('some_shitty_module'))
# This is definitely going to run now.
some_shitty_module.some_function()

fuckitpy (GitHub): https://github.com/ajalt/fuckitpy

0

Source: https://habr.com/ru/post/1664235/


All Articles