<p dir="auto">Currently <code class="notranslate">ArgumentError</code> can be passed a string to use as an error message, but <code class="notranslate">DomainError</code> cannot. It would be nice for the user to have a useful error message also for <code class="notranslate">DomainError</code>s.</p>
<p dir="auto">I would make a PR but I can't find where to do this.</p>
<p dir="auto">Re: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="94512557" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/12121" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/12121/hovercard" href="https://github.com/JuliaLang/julia/pull/12121">#12121</a>'s discussion for <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/tkelman/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tkelman">@tkelman</a>.</p>
<p dir="auto">Right now, <code class="notranslate">DomainError</code> doesn't take any arguments and will throw a <code class="notranslate">MethodError</code> if you try to pass an informative string. This is important because it's used in many performance critical math functions like <code class="notranslate">sqrt</code>, cf. <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/andreasnoack/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/andreasnoack">@andreasnoack</a>. <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/simonster/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/simonster">@simonster</a> chimed in to point out that</p>
<blockquote>
<p dir="auto">We could have DomainError{T&lt;:Union(None,ByteString)} where DomainError() would be a DomainError{None}. I don't think that would be any more expensive when there's no string to be thrown. Would need some changes on the codegen side, though...</p>
</blockquote>
<p dir="auto">and <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/yuyichao/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/yuyichao">@yuyichao</a> mentioned the performance regression discussed at <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="82973421" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/11508" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/11508/hovercard" href="https://github.com/JuliaLang/julia/pull/11508">#11508</a>. <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/simonster/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/simonster">@simonster</a> pointed out that</p>
<blockquote>
<p dir="auto">I'm not sure removing the GC frame would be enough. It would eliminate the additional cost for a DomainError with a string parameter in code that doesn't throw a DomainError, but you'd still have additional overhead if you actually throw a DomainError, which might matter.</p>
</blockquote>
<p dir="auto">What do we want to do going forward? Should we fix codegen, use <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="82973421" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/11508" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/11508/hovercard" href="https://github.com/JuliaLang/julia/pull/11508">#11508</a>, or something else?</p>