# When designing a macro, what is the best error type to throw for what could be see

**URL:** https://discourse.julialang.org/t/when-designing-a-macro-what-is-the-best-error-type-to-throw-for-what-could-be-see/54451
**Category:** General Usage
**Created:** [February 2, 2021, 11:38am UTC](https://discourse.julialang.org/t/when-designing-a-macro-what-is-the-best-error-type-to-throw-for-what-could-be-see/54451 "2021-02-02T11:38:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)
#### Post date: [February 2, 2021, 11:38am UTC](https://discourse.julialang.org/t/when-designing-a-macro-what-is-the-best-error-type-to-throw-for-what-could-be-see/54451/1 "2021-02-02T11:38:30Z")

</div>

When designing a macro, what is the best error type to throw for what could be seen as a “syntax error”?

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1612265889379200?thread_ts=1612265889.379200&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [February 2, 2021, 3:14pm UTC](https://discourse.julialang.org/t/when-designing-a-macro-what-is-the-best-error-type-to-throw-for-what-could-be-see/54451/2 "2021-02-02T15:14:28Z")

</div>

in [DataFramesMeta](https://github.com/JuliaData/DataFramesMeta.jl/blob/master/src/DataFramesMeta.jl) we throw `ArgumentError`s, I guess because the macros in DataFramesMeta are “functon-like”.

---

<div class="post-metadata">

### Author: ![heetbeet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heetbeet/32/20958_2.png) [@heetbeet](https://discourse.julialang.org/u/heetbeet)
#### Post date: [February 3, 2021, 5:07am UTC](https://discourse.julialang.org/t/when-designing-a-macro-what-is-the-best-error-type-to-throw-for-what-could-be-see/54451/3 "2021-02-03T05:07:28Z")

</div>

![](https://global.discourse-cdn.com/julialang/original/3X/5/2/525901d72f90e38a87c70346545bdab60640b110.png)

[Dhairya](https://app.slack.com/team/UC4QQPG4A) [17 hours ago](https://julialang.slack.com/archives/C6A044SQH/p1612267818381900?thread_ts=1612265889.379200&cid=C6A044SQH)

Depends on the context. If you’re producing invalid regular Julia then the compiler would error for you, if it’s a DSL, then you might want to throw a custom exception if you can catch the exact issue - that would be more informative, or else an `ErrorException` would do

![](https://global.discourse-cdn.com/julialang/original/3X/5/a/5aad322befa8f6e2f9a162ed7c1cffdcfbbea85d.jpeg)

[Heetbeet](https://app.slack.com/team/U018FJVBXPD) [17 hours ago](https://julialang.slack.com/archives/C6A044SQH/p1612269104382100?thread_ts=1612265889.379200&cid=C6A044SQH)

Thanks, yes it’s a DSL. I think I’ll then go with ErrorException

---

<div class="post-metadata">

### Author: ![heetbeet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heetbeet/32/20958_2.png) [@heetbeet](https://discourse.julialang.org/u/heetbeet)
#### Post date: [February 3, 2021, 5:09am UTC](https://discourse.julialang.org/t/when-designing-a-macro-what-is-the-best-error-type-to-throw-for-what-could-be-see/54451/4 "2021-02-03T05:09:19Z")

</div>

I see `ErrorException` is basically the same type of error you would get with an actual syntax error. So that is probably the closest to the real deal, but `ArgumentError` is probably the most helpful when you are in the pre-processing the macro arguments phase.
