diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..481da3a3400d0a695a6047b1c7813bfe0c9eb2f4 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Suppressed exceptions for PHP + +Suppressed exceptions are useful for aggregating more exceptions with unreliable resources. + +You want to communicate that process failed, with following list of sibling exceptions that led to this error. + +```php +$remoteSources = []; // classes representing unreliable remote sources + +$exceptions = []; +foreach ($remoteSoures as $remoteSource) { + try { + $remoteSource->fetch(); // unrealiable + } catch (FetchingFailed $e) { + $exceptions[] = $e; + continue; + } +} + +if (count($exceptions) > 0) { + $e = new ProcessingFailed(); + $e->addSuppressed(...$exceptions); + throw $e; +} + +``` \ No newline at end of file