Skip to content

Instantly share code, notes, and snippets.

@aklump
Created May 17, 2024 00:37
Show Gist options
  • Save aklump/b997135e03771a5ac26d61a09d409fe6 to your computer and use it in GitHub Desktop.
Save aklump/b997135e03771a5ac26d61a09d409fe6 to your computer and use it in GitHub Desktop.
How to alter an Exception message.
<?php
$augmented_message = $exception->getMessage() . "\nMy augementation";
$reflected_exception = new \ReflectionObject($exception);
$message_property = $reflected_exception->getProperty('message');
$message_property->setAccessible(TRUE);
$message_property->setValue($exception, $augmented_message);
throw $exception;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment