Answers for "try catch warning php"

PHP
2

try catch in php

Try catch comes under exception handeling concept where using this we control the runtime error and modify the message as we want.

// function created with exception throw
function checkdata($number){
	if($number > 10){
    	throw new Exception("Number is greater than 10");
    }
    return true;
}

// try block starts
try{
	checkdata(15);
  	echo "The number is below 10";
}
// catch block
catch(Exception $e){
	echo "Message :".$e->getMessage();
}

In above code if condition is not satisfied then it will throw exception and which gets caught by catch block and show the error message.
Posted by: Guest on April-16-2020
0

catch warning php

<?php mysqli_connect_error() ?>
<?php error_reporting(E_ALL); ?>
Posted by: Guest on May-26-2021

Browse Popular Code Answers by Language