Hello all,
I was experimenting a bit with daml exceptions, and I came across a situation that I found unexpected and was hoping you could clarify me on this particular topic.
Given the following code:
template Foo
with
p : Party
where
signatory p
controller p can
nonconsuming DoFoo : ()
with
barCid : ContractId Bar
do
try
Foldable.mapA_ (exercise barCid . DoBar) [1..5]
catch error@(Qux msg) -> do
debug $ message error
template Bar
with
p : Party
where
signatory p
controller p can
nonconsuming DoBar : ()
with
n : Int
do
when (n % 5 == 0) do
throw Qux with msg = "Test message"
create Baz with p
return ()
template Baz
with
p : Party
where
signatory p
exception Qux
with
msg : Text
where
message "This is an error - " <> msg
testException : Script ()
testException = script do
let Some p = partyFromText "Party"
fooCid <- submit p do createCmd Foo with p
barCid <- submit p do createCmd Bar with p
submit p do exerciseCmd fooCid DoFoo with barCid
return ()
I expected that no contract “Baz” would exists after the execution of the “DoFoo” choice, as I call the “DoBar” choice inside of the try… catch statement and as such when the execution throws an Exception all previous sub-transactions would have been rolled back.
Thank you in advance