PHP Types of Errors

PHPServer Side ProgrammingProgramming

Introduction

PHP's internal Error types are represented by classes that are inherited from Error class. The Error class implements Throwable interface. Properties and methods of Error class are as follows −

properties

  • message − The error message
  • code − The error code
  • file − The filename where the error happened
  • line − The line where the error happened

methods

  • __construct() − Construct the error object
  • getMessage() − Gets the error message
  • getPrevious() − Returns previous Throwable
  • getCode() − Gets the error code
  • getFile() − Gets the file in which the error occurred
  • getLine() − Gets the line in which the error occurred
  • getTrace() − Gets the stack trace
  • getTraceAsString() − Gets the stack trace as a string
  • __toString() − String representation of the error
  • __clone() − Clone the error

Heirarchy of types of Error classes in PHP is as follows −

Types of Errors

  • Error
    • ArithmeticError
      • DivisionByZeroError
    • AssertionError
    • CompileError
      • ParseError
    • TypeError
      • ArgumentCountError
raja
Published on 21-Sep-2020 14:46:54
Advertisements