# My test case still shows "Unhandled exception" even if I try-catch-ed it?

**URL:** <https://forum.canton.network/t/my-test-case-still-shows-unhandled-exception-even-if-i-try-catch-ed-it/6192>\
**Category:** App Development\
**Tags:** daml-script, daml, test\
**Created:** [March 1, 2023, 3:38am UTC](https://forum.canton.network/t/my-test-case-still-shows-unhandled-exception-even-if-i-try-catch-ed-it/6192 "2023-03-01T03:38:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlie.ng](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@charlie.ng](https://forum.canton.network/u/charlie.ng)\
**Post date:** [March 1, 2023, 3:38am UTC](https://forum.canton.network/t/my-test-case-still-shows-unhandled-exception-even-if-i-try-catch-ed-it/6192/1 "2023-03-01T03:38:53Z")

</div>

Hi there,

Is this a bug when I try to write the test case - testRollback? Because the compiler would still complain that it’s a “Unhandled exception”. And furthermore when I run

> daml test --show-coverage

, it’ll show the test case failed. Any idea from anyone? Thanks in advance.

```haskell
data RollbackErrorCode = 
  VALIDATION_FAILED
  deriving (Eq, Ord, Show)

exception RollbackException
  with
    errorCode : RollbackErrorCode
    errorMsg : Text
  where
    message "RollbackException msg: errorCode - " <> show errorCode <> " , errorMsg - " <> show errorMsg

template TempRollback
  with
    a: Text
    owner: Party
  where
    signatory owner
  
    choice Test : ()
      controller owner
      do
        throw $ RollbackException VALIDATION_FAILED "abc"
        pure ()

testRollback = do
  alice <- allocateParty "Alice"
  cid <- submit alice do
    createCmd TempRollback with
      a = "aapple"
      owner = alice
  try do
    submit alice do
      exerciseCmd cid Test
  catch
    RollbackException _ _ ->
      pure ()
  pure ()

```

---

<div class="post-metadata">

**Author:** ![stefanobaghino-da](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stefanobaghino-da/32/7057_2.png) [@stefanobaghino-da](https://forum.canton.network/u/stefanobaghino-da)\
**Post date:** [March 1, 2023, 6:55am UTC](https://forum.canton.network/t/my-test-case-still-shows-unhandled-exception-even-if-i-try-catch-ed-it/6192/2 "2023-03-01T06:55:02Z")

</div>

You might want to have a look [here](https://discuss.daml.com/t/choice-exercise-error-not-caught-by-try-catch-in-daml-script/6130/4).

tl;dr `try`/`catch` is not currently supported at the top level in Daml Script and Daml Triggers, if you want to catch an error you have to do so as part of a transaction.

---

<div class="post-metadata">

**Author:** ![gyorgybalazsi](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gyorgybalazsi/32/684_2.png) [@gyorgybalazsi](https://forum.canton.network/u/gyorgybalazsi)\
**Post date:** [March 1, 2023, 8:04am UTC](https://forum.canton.network/t/my-test-case-still-shows-unhandled-exception-even-if-i-try-catch-ed-it/6192/3 "2023-03-01T08:04:38Z")

</div>

Extending the answer given by Stefano, this is an example how you can wrap the try/catch in an adhoc contract: [Testing the exact error message returned from failed transactions](https://discuss.daml.com/t/testing-the-exact-error-message-returned-from-failed-transactions/6137)

---

<div class="post-metadata">

**Author:** ![charlie.ng](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@charlie.ng](https://forum.canton.network/u/charlie.ng)\
**Post date:** [March 1, 2023, 8:23am UTC](https://forum.canton.network/t/my-test-case-still-shows-unhandled-exception-even-if-i-try-catch-ed-it/6192/4 "2023-03-01T08:23:54Z")

</div>

Thanks both!! `submitMustFail` works in my case.
