added printed_exception contextmanager
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .utils import typename
|
||||
from contextlib import AbstractContextManager
|
||||
from .utils import typename, singleton
|
||||
|
||||
|
||||
class ChainedException(Exception):
|
||||
@@ -22,3 +23,15 @@ def printable_exception(exc):
|
||||
|
||||
|
||||
|
||||
@singleton
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user