Commit 4c745a6b authored by augustin_s's avatar augustin_s 🐍
Browse files

added printed_exception contextmanager

parent 0c82d8f2
......@@ -5,7 +5,7 @@ from .channels import load_channels, Channels
from .config import Config
from .elog import Elog
from .eval import arithmetic_eval
from .exceptions import ChainedException, printable_exception
from .exceptions import ChainedException, printable_exception, printed_exception
from .ipy import devices
from .json import json_save, json_load
from .marker import Marker, markers
from .utils import typename
from contextlib import AbstractContextManager
from .utils import typename, singleton
class ChainedException(Exception):
......@@ -22,3 +23,15 @@ def printable_exception(exc):
class printed_exception(AbstractContextManager):
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
name = exc_type.__name__
message = exc_val or ""
print("{}: {}".format(name, message))
return True # this causes the with statement to suppress the exception
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment