Error handling

Swoft provides a perfect mechanism for exception and error handling, unlike in normal fpm, where errors are divided into different scene types.

Error scenarios

The division of the scene type: mainly according to the swoole of the callback event range to divide.

In different scenarios, even if an exception or error is thrown in the same place, the way it is handled may be different.

For example: A db throws a DbException Reponse object that you need to process in the HTTP run scene. And in environments such as the CLI, you can only handle it without returning any results

Error scene type

The Swoft\Error\ErrorType scene type that defines the Swoft partition.

<?php declare(strict_types=1);

namespace Swoft\Error;

/**
 * Class ErrorType
 *
 * @since 2.0
 */
final class ErrorType
{
    public const CLI  = 2;
    public const RPC  = 3;
    public const UDP  = 4;
    public const TCP  = 5;
    public const SOCK = 7;
    public const TASK = 8;

    // HTTP server
    public const HTTP = 16;

    // WebSocket server
    public const WS_HS  = 21;
    public const WS_OPN = 22;
    public const WS_MSG = 23;
    public const WS_CLS = 24;

    public const SYS = 85;

    // default
    public const DEF     = 90;
    public const DEFAULT = 90;
}

For the specific use of exception handling, continue to view the next document.

/docs/2.x/en/error/index.html
progress-bar