class_docstr: Abstract base class representing a fail-safe control on the behavior of any
  algorithm.
class_docstr_tok: ["Abstract","base","class","representing","a","fail-safe","control","on","the","behavior","of","any","algorithm","."]
docstr: Handle a TradingControlViolation, either by raising or logging and
  error with information about the failure.
  
  If dynamic information should be displayed as well, pass it in via
  `metadata`.
docstr_tok: ["Handle","a","TradingControlViolation",",","either","by","raising","or","logging","and","error","with","information","about","the","failure",".","If","dynamic","information","should","be","displayed","as","well",",","pass","it","in","via","`","metadata","`","."]
code: def handle_violation(self, asset, amount, datetime, metadata=None):
      """
      Handle a TradingControlViolation, either by raising or logging and
      error with information about the failure.
  
      If dynamic information should be displayed as well, pass it in via
      `metadata`.
      """
      constraint = self._constraint_msg(metadata)
  
      if self.on_error == "fail":
          raise TradingControlViolation(
              asset=asset,
              amount=amount,
              datetime=datetime,
              constraint=constraint,
          )
      elif self.on_error == "log":
          log.error(
              "Order for {amount} shares of {asset} at {dt} "
              "violates trading constraint {constraint}",
              amount=amount,
              asset=asset,
              dt=datetime,
              constraint=constraint,
          )
  
imports: import abc
  import logbook
  import pandas
  from six import with_metaclass
  from catalyst.errors import AccountControlViolation, TradingControlViolation
  from catalyst.constants import LOG_LEVEL
label_desc: Use image node_id 4 for calling the TradingControl obj's underlying member method code with example usage: obj.handle_violation(asset, amount, datetime, metadata) without return types