Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 642 Bytes

Attempt.md

File metadata and controls

30 lines (22 loc) · 642 Bytes

Attempt

This class provides a static method for attempting to run a closure and capturing the result or any exception that is thrown.

Method: attempt

Parameters

  • Closure $closure: The closure to be attempted.

Return

  • AttemptEntity: An instance of AttemptEntity containing the result of the closure, or the exception that was
  • thrown during the attempt.

Example

use Midnite81\Core\Helpers\Attempt;

$result = Attempt::attempt(function () {
    return 'Hello World';
});

if ($result->successful) { 
    echo $result->result;
}

if ($result->hasErrored) {
    echo $result->throwable->getMessage();
}