# How to throw errors?

**URL:** <https://forum.makecode.com/t/how-to-throw-errors/15025>\
**Category:** Help\
**Tags:** extension\
**Created:** [August 22, 2022, 2:53pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025 "2022-08-22T14:53:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [August 22, 2022, 2:53pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025/1 "2022-08-22T14:53:46Z")

</div>

I’m currently writing some TypeScript, (in MakeCode Arcade obviously) and it currently isn’t but I plan on it becoming an extension. It appears that `throw new Error();` is not supported, as `Error` isn’t defined. What are the options available to alert people to runtime errors?

If this style of writing extensions isn’t commonly done, I’m open on other ways to structure my extension. (It’s ✨ something ✨ (that may or may never get released, who knows) that parses images with a specific format, and if the dev pastes in the wrong type of image, or the format is unsupported, or bad values in parsing, I want to throw an error.)

---

<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:** [August 22, 2022, 4:26pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025/2 "2022-08-22T16:26:04Z")

</div>

I belive raising exceptions is a part of the ommited features for the modified TS build MakeCode is using. You could try structuring a custom(?) error splash screen or something of that kind.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [August 22, 2022, 4:29pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025/3 "2022-08-22T16:29:59Z")

</div>

@UnsignedArduino you can throw strings! e.g.

```nohighlight
throw "nice try!"

```

@Sarge we do actually support exceptions!

---

<div class="post-metadata">

**Author:** ![CuteMrMerp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cutemrmerp/32/6671_2.png) [@CuteMrMerp](https://forum.makecode.com/u/CuteMrMerp)\
**Post date:** [August 23, 2022, 5:26pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025/4 "2022-08-23T17:26:21Z")

</div>

You can try `control.panic(/*insert a number*/)`  
The number doesn’t matter

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [August 23, 2022, 7:36pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025/5 "2022-08-23T19:36:13Z")

</div>

I’ve tried that, but a single number isn’t really that informative 😅  
Plus, I’m not sure which numbers are already used by Arcade, because I’m not sure how much [this page](https://makecode.com/js/errorcodes) covers.

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [August 23, 2022, 8:37pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025/6 "2022-08-23T20:37:01Z")

</div>

wait you want a extension to throw errors?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [August 23, 2022, 8:41pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025/7 "2022-08-23T20:41:37Z")

</div>

if you really want to use a panic code you can, but you want to use something that isn’t in the 9XXs or the 0XXs since those are reserved for system errors.

all of the codes that we use are here:

> <https://github.com/microsoft/pxt-common-packages/blob/master/libs/base/control.ts#L15>

but really, a string is so much easier to read 🙂

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [August 23, 2022, 11:42pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025/8 "2022-08-23T23:42:17Z")

</div>

Well, I don’t think I would need an extension, I just needed a way to crash the program, hopefully with an informative message and it appears that `throw "string";` does what I want.

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [August 24, 2022, 5:05pm UTC](https://forum.makecode.com/t/how-to-throw-errors/15025/9 "2022-08-24T17:05:48Z")

</div>

what if you do every game update then put a music block inside of it it makes me crash btw it has to be 1 milisecond
