Error
Contains the error exception.
Instances of this class are immutable and not affected by any method calls.
Static Methods
empty
public static function empty(): self;
Makes a new Error
containing a RuntimeException
with no message.
withException
public static function withException(Throwable $exception): self;
Makes a new Error
with the given exception
.
withMessage
public static function withMessage(string $message): self;
Makes a new Error
containing a RuntimeException
with the given message
.
Methods
andThen
public function andThen(Ok|Error|Closure $result): self;
Returns the original instance, ignoring the given result
.
exception
public function exception(): Throwable;
Returns the error exception.
hasException
public function hasException(): true;
Returns true
, since Error
instances always contain an exception.
hasMessage
public function hasMessage(): bool;
Returns whether the result provides a message.
hasValue
public function hasValue(): false;
Returns false
, since Error
instances never contain a value.
isError
public function isError(): true;
Returns whether the result is an error.
isOk
public function isOk(): false;
Returns whether the result is a success.
message
public function message(): string;
Returns the result's message, if any.
onFailure
public function onFailure(Closure $action): self;
Performs the given action
on the encapsulated value. Returns the original instance unchanged.
Parameters:
$action
a Closure
that receives the error exception.
onSuccess
public function onSuccess(Closure $action): self;
Returns the original instance without performing the given action
.
Parameters:
$action
a Closure
that receives the success value.
or
public function or(mixed $value): mixed;
Returns given value
.
Note: If the value
is a closure, this method will call it and return the output.
orDie
public function orDie(int|string $status = null): never;
Terminates execution of the script.
orElse
public function orElse(Ok|Error|Closure $result): Ok|Error;
Returns the given result
.
Note: If the result
is a closure, this method will call it and return its output.
orFail
public function orFail(): never;
Throws the error exception.
orFalse
public function orFalse(): false;
Returns false
.
orNull
public function orNull(): null;
Returns null
.
orThrow
public function orThrow(Throwable|Closure $exception): never;
Throws the given exception.
Note: If exception
is a closure, this method will call it and throw the output.
value
public function value(): null;
Returns null
, since Error
instances never contain a value.