Exception refactoring
I have a bunch of old code that does something like this:
use Application\Exception;
try {
...
}
catch (\Exception $e) {
if (DEBUGMODE) throw $e;
throw new Exception('Invalid request.');
}
This pattern is unfortunately repeated in hundreds of places around the code.
I'd like to replace it with something like:
use Application\InvalidRequestException;
try {
...
}
catch (\Exception $e) {
throw new InvalidRequestException($e);
}
So in InvalidRequestException I can do some appropriate logging and then display either the detailed error or a general "Invalid request" error depending on the environment.
Is this achievable with PHPStorm code refactoring tools somehow? I cannot do a blanket search & replace on the use statement as there might be other Application\Exceptions thrown that need to stay intact.
Please sign in to leave a comment.