Raising exceptions โ
Once an exception is raised, it cannot be caught.
Error messages may take a lot of space in smart contracts.
Have a look at Exception Optimization Levels.
Exceptions cannot be caught, the whole operation is backtracked if an exception occurs.
FAILWITH โ
sp.failwith
aborts the current transaction and raises a message of arbitrary type.
python
@sp.entrypoint
def ep(self):
sp.if self.data.x > 10:
sp.failwith("x is bigger than 10")
Besides sp.failwith
, sp.verify
and sp.verify_equal
, exceptions can also be raised by other constructions:
Accessing fields
my_map[x]
The exception raised is a pair containing the
(x, my_map)
.Opening variants
.open_some(<message>)
This may fail with
sp.unit
.Dividing by zero
1ย /ย 0
Variable step in a range which is 0
sp.for i in sp.range(1,ย 10,ย stepย =ย 0)