# Are try catch statements supported?

**URL:** <https://forum.makecode.com/t/are-try-catch-statements-supported/19117>\
**Category:** Help\
**Tags:** extension\
**Created:** [April 11, 2023, 6:13pm UTC](https://forum.makecode.com/t/are-try-catch-statements-supported/19117 "2023-04-11T18:13:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 11, 2023, 6:13pm UTC](https://forum.makecode.com/t/are-try-catch-statements-supported/19117/1 "2023-04-11T18:13:25Z")

</div>

I am writing an extension with useful utility blocks. Two of them are try and try-catch blocks, but it seems like they don’t work when a block that causes errors is put in.  
Here’s the code for the try-catch block, another issue I have is that I can’t have multiple “mouths” (where you can put code in):

```auto
export function tryCatchCode(tryCode: () => void, catchCode: (errorName: string) => void): void {
    try {
        tryCode();
    } catch (error) {
        catchCode(error.name);
    }
}

```

Is it possible to have two “mouths” in a single block and are try statements supported?

---

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 13, 2023, 8:35pm UTC](https://forum.makecode.com/t/are-try-catch-statements-supported/19117/2 "2023-04-13T20:35:34Z")

</div>

Thought it was because it can’t bypass memory errors, but even with casting on null the try statement still fails and crashes. Doing try statements plainly on JavaScript code does work but as a block in an extension it doesn’t.

---

<div class="post-metadata">

**Author:** ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)\
**Post date:** [April 14, 2023, 4:46pm UTC](https://forum.makecode.com/t/are-try-catch-statements-supported/19117/4 "2023-04-14T16:46:09Z")

</div>

I think blocks might not support try-catch statements. The doc I linked in another thread refers to the JavaScript / TS features implemented

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [April 15, 2023, 9:28pm UTC](https://forum.makecode.com/t/are-try-catch-statements-supported/19117/6 "2023-04-15T21:28:43Z")

</div>

Good questions!

1. Currently we don’t have authoring to support multiple function handlers as parameters (to make something like an if / else block) but it’s something we can consider – I’ve wanted it at times before but never enough to actually make it work 🙂
2. It looks like try / catch is only working with explicit `throw "abc"` calls at the moment, as far as I can tell – which would make this make sense with null pointer exceptions being the most common error you’ll likely hit. I filed this as an issue [https://github.com/microsoft/pxt-arcade/issues/5852](https://github.com/microsoft/pxt-arcade/issues/5852) so it can be discussed more over there~

---

<div class="post-metadata">

**Author:** ![EpicKitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/epickitty/32/8358_2.png) [@EpicKitty](https://forum.makecode.com/u/EpicKitty)\
**Post date:** [April 16, 2023, 10:17pm UTC](https://forum.makecode.com/t/are-try-catch-statements-supported/19117/7 "2023-04-16T22:17:36Z")

</div>

1. Where can I suggest a suggestion on the GitHub of Arcade? There doesn’t seem to be a suggest tag on the issues tab?
2. (Can’t log in to GitHub right now, sorry about that!) Wouldn’t it be dangerous to still try and catch errors that’s about the memory? Also just to be sure, I’m talking about running the code in the function handler (“Mouth’s”)in try statements in extensions.

Thank you for answering!

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [April 16, 2023, 10:28pm UTC](https://forum.makecode.com/t/are-try-catch-statements-supported/19117/8 "2023-04-16T22:28:31Z")

</div>

1. Just file an issue, I believe it’ll give an option for bug report or enhancement (if so, just choose enhancement) - one of the members of our team will triage it when we get time and give it appropriate tags
2. Maybe! I mentioned in the issue that it should either be supported or documented that it’s not- I haven’t looked at the code that handles it recently enough to know how hard it’d be to support. And yes, that’s what I meant as well - right now our block logic checks for event handles and adds a ‘mouth’ if there is a function as a parameter, this would be theoretically adding support for two or more functions as parameters. Have to double check, we might have an issue for that already otherwise i can file one on monday~

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [April 18, 2023, 1:53am UTC](https://forum.makecode.com/t/are-try-catch-statements-supported/19117/9 "2023-04-18T01:53:12Z")

</div>

I went ahead and filed the request for multiple handler parameters [here](https://github.com/microsoft/pxt-arcade/issues/5854), I don’t know when we’ll get the chance to make it work but if anything changes that issue will be updated accordingly 🙂
