HH\Lib\OS\Exception
Requires the Hack Standard Library - Experimental Additions to be installed.
Facebook Engineer?
This function is available as OS\Exception()
in Facebook's www repository.
Base class for exceptions reported by primitive native operations
This is used for errors that are indicated by errno
, herror
, or
similar interfaces covered by the ErrorCode
enum.
Subclasses exist for some specific ErrorCode
values, such as:
ChildProcessException
(ECHILD
)ConnectionException
and its' subclasses,BrokenPipeException
(EPIPE
,ESHUTDOWN
),ConnectionAbortedException
(ECONNABORTED
),ConnectionRefusedException
(ECONNREFUSED
), andConnectionResetException
(ECONNRESET
)AlreadyExistsException
(EEXIST
)NotFoundException
(ENOENT
)IsADirectoryException
(EISDIR
)IsNotADirectoryException
(ENOTDIR
)PermissionException
(EACCESS
,EPERM
)ProcessLookupException
(ESRCH
)TimeoutError
(ETIMEDOUT
)
It is strongly recommended to catch subclasses instead of this class if a suitable subclass is defined; for example:
// ANTIPATTERN:
catch (OS\Exception $e) {
if ($e->getErrorCode() === OS\ErrorCode::ENOENT) {
do_stuff();
}
}
// RECOMMENDED:
catch (OS\NotFoundException $_) {
do_stuff();
}
If a suitable subclass is not defined, the antipattern is unavoidable.
Interface Synopsis
namespace HH\Lib\OS;
class Exception extends \Exception {...}