Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

getCode()

Example

Throw an exception and display its code.

<?php
try {
  throw new Exception(“An error occurred”120);
catch(Exception $e) {
  echo “Error code: “ . $e->getCode();
}
?>

Definition and Usage

The getCode() method returns an integer that can be used to identify the exception.

Syntax

$exception->getCode()

Technical Details

 

Return Value:

Returns an integer value.