Home >Backend Development >PHP Tutorial >PHP Throwable interface
In PHP 7, the Throwable interface acts as any object that can be used as a parameter for a throw statement The basis, including errors and exceptions. Both the Error and Exception classes (from which predefined and user-defined error and exception classes are derived, respectively) implement the Throwable interface. The following abstract methods are defined in the Throwable interface -
Throwable { /* Methods */ abstract public getMessage ( void ) : string abstract public getCode ( void ) : int abstract public getFile ( void ) : string abstract public getLine ( void ) : int abstract public getTrace ( void ) : array abstract public getTraceAsString ( void ) : string abstract public getPrevious ( void ) : Throwable abstract public __toString ( void ) : string }
getMessage (void) - string -> Return and throw objects associated messages.
getCode (void) - int -> Returns the error code associated with the thrown object.
getFile ( void ) − string -> Gets the name of the file where the thrown object is created.
getLine ( void ) − int -> Returns the line number where the thrown object is instantiated.
getTrace ( void ) − array -> Returns the stack trace as an array.
getTraceAsString ( void ) − string -> Returns the stack trace as a string.
getPrevious ( void ) - Throwable -> Returns any previous Throwable (supplied as the third argument to Exception::__construct()).
__toString ( void ) − string -> Get the string representation of the thrown object
The above is the detailed content of PHP Throwable interface. For more information, please follow other related articles on the PHP Chinese website!