@@ -139,6 +139,24 @@ $attempt = Attempt::of(static fn() => 1/0)
139139
140140Here ` #!php $attempt ` contains an ` \Exception ` because the first ` Attempt ` raised a ` DivisionByZeroError ` .
141141
142+ ## ` ->mapErrorCase() `
143+
144+ This is similar to ` mapError ` except you can specify the type of error you want to change (like in a ` catch ` statement).
145+
146+ ``` php
147+ $attempt = Attempt::of(static fn() => 1/0)
148+ ->mapErrorCase(
149+ \DivisionByZeroError::class,
150+ static fn(\DivisionByZeroError $e) => new \Exception('Division by zero, fix the code'),
151+ )
152+ ->mapError(static fn(\Throwable $e) => new \Exception('something bad happened', 0, $e));
153+ ```
154+
155+ !!! warning ""
156+ It uses ` instanceof ` to check the error case. This means the order in which you apply these calls is important!
157+
158+ This is to match the behaviour of the `catch` statement.
159+
142160## ` ->recover() `
143161
144162This will allow you to recover in case of a previous error.
@@ -150,6 +168,26 @@ $attempt = Attempt::of(static fn() => 1/0)
150168
151169Here ` #!php $attempt ` is ` #!php 42 ` because the first ` Attempt ` raised a ` DivisionByZeroError ` .
152170
171+ ## ` ->recoverCase() `
172+
173+ This is similar to ` recover ` except you can specify the type of error you want to recover (like in a ` catch ` statement).
174+
175+ ``` php
176+ $attempt = Attempt::of(static fn() => 1/0)
177+ ->recoverCase(
178+ \DivisionByZeroError::class,
179+ static fn(\DivisionByZeroError $e) => Attempt::result(0),
180+ )
181+ ->recover(static fn(\Throwable $e) => Attempt::result(42));
182+ ```
183+
184+ Here ` #!php $attempt ` is ` #!php 0 ` because the first ` Attempt ` raised a ` DivisionByZeroError ` .
185+
186+ !!! warning ""
187+ It uses ` instanceof ` to check the error case. This means the order in which you apply these calls is important!
188+
189+ This is to match the behaviour of the `catch` statement.
190+
153191## ` ->xrecover() `
154192
155193This behaves like [ ` ->recover() ` ] ( #-recover ) except when conjointly used with [ ` ->guard() ` ] ( #-guard ) . Guarded errors can't be recovered.
0 commit comments