Home > Backend Development > PHP Tutorial > PHP Throwable interface

PHP Throwable interface

PHPz
Release: 2023-09-12 21:42:02
forward
1635 people have browsed it

PHP Throwable接口

Introduction

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 -

Syntax

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
}
Copy after login

Method

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template