This question already has an answer here:

I'm wondering if a modifier function can use events while still throwing afterwards?

I'm looking for a way to have a "catch error" events that would trigger if it fails for X or Z modifier.

Anyone knows a way to do this ?

marked as duplicate by Xavier Leprêtre B9lab, niksmac, Nicolas Massart, Matthew Schmidt, eth Sep 7 '16 at 1:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


No, neither modifiers nor the body of the code can use events if they throw errors. Throwing an error reverts everything about the transaction except the gas usage, so it doesn't leave anything written to the event log.

The alternative is to use return codes and events to track whether something went wrong instead of throwing errors, but that means you need to be a bit more careful about your control logic, because you need to detect the error conditions you're interested in before you start writing data or updating balances.

  • there really needs to be a throw-catch arrangement, or at least goto, or exception logic gets very complicated with if-else statements. Perhaps this is a different question... – Paul S Sep 7 '16 at 0:56

You may wish to consider if you need to throw.

For reference, a throw reverts every change in the transaction so far. Solidity helpfully continues the reversion down the stack (although there are ways around this). All gas is consumed in the process.

Considering all this, a throw may be overkill if the transaction can be reversed manually. If the modifier is to prevent everyone except the owner from withdrawing money, there's not much need to undo the transaction. If the modifier is to prevent people from depositing money, then it makes perfect sense to throw.

Not the answer you're looking for? Browse other questions tagged or ask your own question.