rfc:suppressed_exceptions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:suppressed_exceptions [2019/04/04 16:55] – danack | rfc:suppressed_exceptions [2019/04/04 17:43] (current) – danack | ||
---|---|---|---|
Line 8: | Line 8: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | In some scenarios | + | Currently in PHP there are some scenarios |
<code php> | <code php> | ||
function fetchDataOverNetwork() { | function fetchDataOverNetwork() { | ||
- | |||
- | $networkExceptions = []; | ||
for ($i = 0; $i < MAX_ATTEMPTS; | for ($i = 0; $i < MAX_ATTEMPTS; | ||
Line 20: | Line 18: | ||
return foo(); | return foo(); | ||
} | } | ||
- | catch (NetworkException $ne) { | + | catch (NetworkException $networkException) { |
- | $networkExceptions[] = $ne; | + | |
} | } | ||
} | } | ||
Line 129: | Line 127: | ||
As per the resource exception sometimes it is necessary to add suppressed exception to an exception that has been caught and is going to be re-thrown. | As per the resource exception sometimes it is necessary to add suppressed exception to an exception that has been caught and is going to be re-thrown. | ||
+ | |||
+ | |||
+ | ===== Why not just use the ' | ||
+ | |||
+ | The constructor for Exceptions allows a ' | ||
+ | |||
+ | <code php> | ||
+ | function foo() | ||
+ | { | ||
+ | try { | ||
+ | bar(); | ||
+ | } | ||
+ | // LogicException is part of core | ||
+ | catch (LogicException $le) { | ||
+ | throw new FooException( | ||
+ | " | ||
+ | 0, | ||
+ | $le | ||
+ | ) | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In this example, only one thing has gone wrong unexpectedly and so the FooException and LogicException are representing a single unexpected error. As it is a single error, this exception only needs to be logged once. | ||
+ | |||
+ | In the resource exception example, the fact that there was an exception calling ' | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Additionally, | ||
+ | |||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== |
rfc/suppressed_exceptions.1554396914.txt.gz · Last modified: 2019/04/04 16:55 by danack