Re: [RFC] Optional Catch Block Body

From: Date: Thu, 31 Jul 2025 09:16:10 +0000
Subject: Re: [RFC] Optional Catch Block Body
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-128337@lists.php.net to get a copy of this message
On Thu, Jul 31, 2025 at 10:12 AM Rob Landers <rob@bottled.codes> wrote: > my empty catches have lengthy comments describing why they are empty in > case a user steps into it, so they can better understand how the framework > works. > > — Rob > Agree. I prefer to describe why I've wrote it: try { ... } catch (...) { /** * We don't care If it's broken, because we should go further. */ } A few cases from my side: $decoded = []; try { $decoded = json_decode($unknownData, asArray: true); } catch (JsonException); Almost the same as try { $decoded = json_decode($unknownData, asArray: true); } catch (JsonException) { $decoded = []; } try { doSmth() } catch (RaceConditionException $e) { // ok, skip 'cause another worker did the same } -- Best regards, Dmitrii Derepko. @xepozz

« previous php.internals (#128337) next »