snowman15 Posted November 1, 2007 Share Posted November 1, 2007 This script isn't working at all. There is an include file that holds the functions, and then the actual php file that runs this really easy script and its not working! include file: (do not change, it is supposed to be right) <?php function formatException(Exception $e) { return "Error {$e->getCode()}: {$e->getMessage()} " . "(line: {$e->getline()} of {$e->getfile()})"; } function average($numArray) { if (! is_array($numArray)) throw new Exception("Input parameter not an array", 10001); $total = 0; $itemCount = count($numArray); if ($itemCount == 0) throw new Exception("Number of items to average = 0", 10002); foreach ($numArray as $i) { if (is_int($i) || is_float($i)) $total += $i; else throw new Exception("Array element not numeric", 10003); } return $total / $itemCount; } ?> What is wrong below? <?php include('exam1p4func.inc.php'); $myArray = array(10, 15, 17, 23, 9, 11, 13); $myString = "I am not an array"; $emptyArray = array(); $badArray = array(1, 2.2, 3.25, "four", 5.0, 66); try { $answer=average($myArray); echo $answer; } catch (Exception $em) { echo $em; } } ?> something is wrong in the php file that runs the function average() Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/75597-exception-help/ Share on other sites More sharing options...
snowman15 Posted November 1, 2007 Author Share Posted November 1, 2007 anything? Quote Link to comment https://forums.phpfreaks.com/topic/75597-exception-help/#findComment-382541 Share on other sites More sharing options...
Guest Posted November 1, 2007 Share Posted November 1, 2007 Hey, it works for me. However, that's only after I removed that trailing curly brace at the end of the php file that runs average() ... { echo $em; } } <--- remove this ... Quote Link to comment https://forums.phpfreaks.com/topic/75597-exception-help/#findComment-382547 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.