Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def raise_exception(self, node, exc=None, msg='', expr=None,
lineno=None):
"""Add an exception."""
if self.error is None:
self.error = []
if expr is None:
expr = self.expr
if len(self.error) > 0 and not isinstance(node, ast.Module):
msg = '%s' % msg
err = ExceptionHolder(node, exc=exc, msg=msg, expr=expr, lineno=lineno)
self._interrupt = ast.Break()
self.error.append(err)
if self.error_msg is None:
self.error_msg = "at expr='%s'" % (self.expr)
elif len(msg) > 0:
self.error_msg = msg
if exc is None:
try:
exc = self.error[0].exc
except:
exc = RuntimeError
raise exc(self.error_msg)