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

Exception()

Example

<?php

throw new Exception(“Division by zero”1);

?>

Definition and Usage

The Exception() constructor is used to create an Exception object and initialize its properties.

Syntax

new Exception(message, code, previous)

Parameter Values

Parameter

Description

message

Optional. A string explaining the reason for the exception.

code

Optional. An integer used to differentiate this exception from others of the same type.

previous

Optional. If this exception was thrown within a catch block of another exception, it is recommended to pass the original exception into this parameter.