RFR: 8255082: HotSpot Style Guide should permit noexcept [v3]

Vladimir Kozlov kvn at openjdk.org
Fri Jun 20 16:59:29 UTC 2025


On Fri, 20 Jun 2025 15:56:52 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> doc/hotspot-style.md line 1153:
>> 
>>> 1151: HotSpot code can assume no exceptions will ever be thrown, even from functions
>>> 1152: not declared `noexcept`. So HotSpot code doesn't ever need to check, either
>>> 1153: with conditional exception specifications or with `noexcept` expressions.
>> 
>> "doesn't ever need to check" - what check? We still need to have nullptr checks. Right?
>
> If a `new` expression is calling a non-throwing variant then the caller of the
> `new` expression should be handling the possible null result. An assert is
> generally not the appropriate "handling". If one isn't prepared to handle a
> null result then don't call the variant that might return that.
> 
> In our typical usage, if calling a potentially throwing variant, it will never
> return null, instead terminating the program. In such a case, there's no need
> for a null check by the caller, as we know that case is handled inside the
> call.

In short, `noexcept` will indicate that caller have to check for nullptr and handle it (yes, not assert).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25574#discussion_r2159378337


More information about the hotspot-dev mailing list