PHP Classes

File: throw_exception.php

Recommend this page to a friend!
  Classes of Allan Kibet  >  Learn New PHP 8 Features  >  throw_exception.php  >  Download  
File: throw_exception.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Learn New PHP 8 Features
Examples of how to use PHP 8 new features
Author: By
Last change:
Date: 7 months ago
Size: 231 bytes
 

Contents

Class file image Download
<?php

function divide(int $a, int $b): float {
    if (
$b == 0) {
       
// You can throw an exception within any expression
       
throw new Exception("Can't divide by 0");
    }
    return
$a / $b;
}

var_dump(divide(100,0));

For more information send a message to info at phpclasses dot org.