Jaymon / pout

Python pretty print on steroids
MIT License
29 stars 0 forks source link

easy exception printing #59

Closed Jaymon closed 4 years ago

Jaymon commented 4 years ago

There are times when I get errors in properties, something like:

class Foo(object):
    @property
    def bar(self):
        return self.get_bar()

    def get_bar(self):
        raise AttributeError()

Properties swallow the error so I'll modify bar to catch the error so I can see what is happening:

@property
def bar(self):
    try
        return self.get_bar()
    catch Exception as e:
         pout.v(e)
         raise

It would be cool if I could do this:

@property
def bar(self):
    with pout.e():
        return self.get_bar()

and pout.e() will just print any exceptions and then raise them again.