Encapsulate exceptions with context manager