Should I use an exception to pass an instance of my object?

From: Date: Sat, 24 Oct 2020 09:13:44 +0000
Subject: Should I use an exception to pass an instance of my object?
Groups: php.general 
Request: Send a blank email to php-general+get-327343@lists.php.net to get a copy of this message
I'm facing a situation where I want to use an exception in my __construct method to notify the caller that the input data is invalid. But I because I want to avoid having to use a static constructor method or validate the data before the __construct call I thought I would just modify the data based on my needs and at the very end of __construct throw a custom exception what holds the instance of $this so it can still be used at the callers side. Example: https://3v4l.org/pbIWR Should I do it?

« previous php.general (#327343) next »