Abnormal knowledge in PHP

First, thread

First thing clear: exceptions and errors are not the same thing.

An exception (Exception) is an exception or an event procedure arising in the implementation of a program, it interrupts the normal operation instruction, jump to the other program modules continue.

The basic format:

the try {
     // perform abnormality detection code portion, such as throw new Exception ( 'manual throw an exception');       
} the catch ( Exception  $ E ) {
     // perform exception trap handling 
} the finally {
     // No matter abnormalities are not executed    
}

Description:

  • ... ... try a catch corresponding to at least try a catch, catch can not appear alone
  • PHP, the need to manually throw an exception
  • throw keyword starting exception handling mechanism, is a sentence structure, you must pass an object to it as a value
  • The exception will be thrown catch corresponding capture

Second, the expansion of the built-in Exception class

? < PHP
 class  Exception {
     // exception message 
    protected  String  $ the Message ;
     // user-defined exception number 
    protected int $ code ;
     // filename exception of 
    protected  String  $ File ;
     // line number of the exception 
    protected int $ Line ; 

    // Constructors 
    public the __construct ([ String  $ message = "" [, int $ code = 0 [, the Throwable $ Previous = NULL ]]])
     // return exception information
    Final  public getMessage (void): String 
    // returns abnormal number 
    Final  public getCode (void): int
     // Returns the file name of the exception 
    Final  public getFile (void): String 
    // Returns the line number of the exception 
    Final  public getLine ( void): int
     Final  public getTrace (void): Array 
    // formatted string into getTrace () information 
    Final  public getTraceAsString (void): string 

    // output object information 
    public the __toString (void): string 
}

Exception base class see:  https://www.php.net/manual/zh/class.exception.php

 

Guess you like

Origin www.cnblogs.com/cshaptx4869/p/11210837.html