How do I detect a margin call after failed option assignment (because of unsufficient buying power)?

I would like to throw an exception and stop the backtesting.