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


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