PHP Error handling

Hello, I am making a grade calculation application, I was wondering if anyone could help me with some error handling examples, the code will be listed below.

--------------function page

function getTotal($input_text){
$lines = explode("newline", $input_text);    
$total_marks = 0;    
  foreach ($lines as $line) {        
  $line_array = explode(",", $line);       
 $total_marks += $line_array[1];   
 }  
 return $total_marks;
}

---------------------index.php page

<?php

header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
require('functions.inc.php');
$output = array(
"error" => false,
"string" => "",
"answer" => 0
);
$input_text = $_REQUEST['input_text'];
$answer=getTotal($input_text);
$output['string']=$input_text."=".$answer;
$output['answer']=$answer;
echo json_encode($output);
exit();
Sponsor our Newsletter | Privacy Policy | Terms of Service