C++ Logo

std-proposals

Advanced search

Re: [std-proposals] try else syntax for validity check

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 18 Feb 2025 17:43:57 -0300
On Tuesday, 18 February 2025 17:42:01 Brasilia Standard Time Filip wrote:
> I know that I can throw meaningful exceptions and check every pointer before
> dereference. What I want is to help me and others avoid mistaking one or
> more dereferences. I believe that this is about safety and usability, it is
> easier to write:
>
> try p1->p2->get(0);
> catch (nullptr) …

The problem is that this syntax is already permitted and you're asking for
everyone's try blocks to be slower at every pointer that gets dereferenced.

Wouldn't it be better to have a ?-> operator instead?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-02-18 20:44:02