Skip to content
On this page

Exceptions

On Tezos, exceptions cannot be caught; there is no way to intercept exceptions and trigger alternate behavior. If an exception occurs, the entire transaction is backtracked. In this case, all of the operations are canceled and any completed operations are reverted, as if the initial call to the contract never happened.

INFO

A transaction starts with a call from a user account (sometimes known as an implicit account) and includes all subsequent operations, such as transfers, contract calls, and contract originations that the initial call triggered.

For example, if a user account calls contract A, contract A calls contract B, contract B calls contract C, and contract C raises an exception, all calls are reverted, including the original call to contract A. The storage states of all of these contracts and the balances of all related accounts are set back to their state before the original call, as if that call never happened.

raise  x: t → 

Aborts the current transaction and raises an error x of type t.

smartpy
raise "NotAdmin"
raise ("TOKEN_UNDEFINED", 404)
assert  x: bool, exception: t → 

Checks that x evaluates to True and raises an exception if it doesn’t.

smartpy
assert sp.sender == self.data.administrator, "NotAdmin"

Exception flags

You can control the text of error messages with scenario flags to provide more information while debugging or less information to save fees. See Test scenarios for more information.