# How to indicate failed operations?

**URL:** <https://forum.dfinity.org/t/how-to-indicate-failed-operations/20074>\
**Category:** Motoko\
**Created:** [May 18, 2023, 10:56am UTC](https://forum.dfinity.org/t/how-to-indicate-failed-operations/20074 "2023-05-18T10:56:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [May 18, 2023, 10:56am UTC](https://forum.dfinity.org/t/how-to-indicate-failed-operations/20074/1 "2023-05-18T10:56:09Z")

</div>

Should failed operations (e.g. deadlocks) be marked `reject` or `Debug.trap`? Please give examples of using both.

Is it true that `Debug.trap` is intended _only_ for catching errors in code (not input errors or for example overload of the system)?

As `Debug.trap` rollbacks unlike `reject`, isn’t it wise to use it for any situation that needs rollback, not only for indicating coding errors? Why was `reject` chosen by language designers not to rollback?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [May 19, 2023, 8:21am UTC](https://forum.dfinity.org/t/how-to-indicate-failed-operations/20074/2 "2023-05-19T08:21:03Z")

</div>

I guess it depends on your needs. Does you application work better if you roll back or not?

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [May 19, 2023, 1:47pm UTC](https://forum.dfinity.org/t/how-to-indicate-failed-operations/20074/3 "2023-05-19T13:47:41Z")

</div>

I think, it works better if I rollback. (I am still however a novice in IC development.)

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [May 19, 2023, 2:44pm UTC](https://forum.dfinity.org/t/how-to-indicate-failed-operations/20074/4 "2023-05-19T14:44:42Z")

</div>

I am also looking for a “formula” for what the correct behaviour in case of failed operations is, but couldn’t find one yet. (See my related question [Is trapping better than returning an error?](https://forum.dfinity.org/t/is-trapping-better-than-returning-an-error/19963))

I think you are free to choose between trap and reject, depending on whether you want to roll back or not. The handling on the caller side is essentially the same. The caller sees an error code and an error message (Text). I don’t think trap is reserved for certain situations.

That said, even in error cases it could be that you do not want to roll back, even if you normally would. For example, a canister might want to track who (which caller) made the failed call because the canister might still want to charge a fee for the call.
