From dee0a2bfaca04578ce13eb5df55238764711ef9b Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Tue, 12 Sep 2017 12:54:08 +0200 Subject: [PATCH 1/2] Retain previous exception on catch --- src/Rand.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Rand.php b/src/Rand.php index ba5d5aa..67bc2eb 100644 --- a/src/Rand.php +++ b/src/Rand.php @@ -37,16 +37,22 @@ public static function getBytes($length) return random_bytes($length); } catch (\TypeError $e) { throw new Exception\InvalidArgumentException( - 'Invalid parameter provided to getBytes(length)' + 'Invalid parameter provided to getBytes(length)', + 0, + $e ); } catch (\Error $e) { throw new Exception\DomainException( - 'The length must be a positive number in getBytes(length)' + 'The length must be a positive number in getBytes(length)', + 0, + $e ); } catch (\Exception $e) { throw new Exception\RuntimeException( 'This PHP environment doesn\'t support secure random number generation. ' . - 'Please consider upgrading to PHP 7' + 'Please consider upgrading to PHP 7', + 0, + $e ); } } @@ -76,16 +82,22 @@ public static function getInteger($min, $max) return random_int($min, $max); } catch (\TypeError $e) { throw new Exception\InvalidArgumentException( - 'Invalid parameters provided to getInteger(min, max)' + 'Invalid parameters provided to getInteger(min, max)', + 0, + $e ); } catch (\Error $e) { throw new Exception\DomainException( - 'The min parameter must be lower than max in getInteger(min, max)' + 'The min parameter must be lower than max in getInteger(min, max)', + 0, + $e ); } catch (\Exception $e) { throw new Exception\RuntimeException( 'This PHP environment doesn\'t support secure random number generation. ' . - 'Please consider upgrading to PHP 7' + 'Please consider upgrading to PHP 7', + 0, + $e ); } } From 92f56cacb2b91195e51d9dcfac8789a3554625ee Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 26 Apr 2018 16:14:36 -0500 Subject: [PATCH 2/2] Adds CHANGELOG entry for #29 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bde709..a08e241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ All notable changes to this project will be documented in this file, in reverse - Nothing. +### Changed + +- [#29](https://github.com/zendframework/zend-math/pull/29) modifies how caught exceptions are re-thrown; all such cases now provide + the original exception as the previous exception. + ### Deprecated - Nothing.