try catch ?
Posted: Thu Oct 13, 2005 1:17 pm
I know in C there is the try/catch functions. I have been searching and appearently there is the same basic ability it PHP aswell. But I can't seem to get mine to work. It stops everything from working.
My code is as follows
i only see the text if i comment every try / catch
what do i have wrong with the try / catch portion. is there extra functions needed for it to work? or is there something else i need to do?
Thanks for you help.
My code is as follows
Code: Select all
<?php
function DecayIt ($origActive, $halfLife, $origTime, $origDate, $currTime, $currDate) {
$origActive = floatval($origActive);
$halfLife = floatval($halfLife);
$origTime = TDateTime($origTime, 1);
$origDate = TDateTime($origDate, 0);
$currTime = TDateTime($currTime, 1);
$currDate = TDateTime($currDate, 0);
$currentActivity = 0.0;
$nCurrentActivity = 0.0;
$fExp = 0.0;
$fExp1 = 0.0;
$fMult = 0.0;
$elapsedTime = $currTime + $currDate;
if ($elapsedTime == 0.0) {
return 0.0;
}
$elapsedTime = ($currTime + $currDate) - ($origTime + $origDate);
$elapsedTime = $elapsedTime * 24.0;
if ($elapsedTime != 0.0) {
$elapsedTime = floatval(number_format($elapsedTime, 3, '.', ''));
} else {
return $origActivity;
}
if ($halfLife > 0) {
$fMult = -0.693 * $elapsedTime;
try
{
$fExp = $fMult / $halfLife;
if ($fExp >= 11356.50) {
$fExp1 = 0.0;
} else {
try
{
$fExp1 = exp($fExp);
}
catch ($e)
{
$fExp1 = 0.0;
}
}
$nCurrentActivity = $origActivity * $fExp1;
}
catch($e)
{
$nCurrentActivity = 0.0;
}
} else {
$nCurrentActivity = 0.0;
}
$currentActivity = $nCurrentActivity;
try
{
if ($currentActivity == 0) {
$currentActivity = 0.0;
}
}
catch ($e)
{
$currentActivity = 0.0;
}
return($currentActivity);
}
// this is just to test, not used in the real page
echo 'hi<br><br><br>'; // prints hi
$time = TDateTime('12:34', 1);
echo $time.'<br>'; // prints 0.52361111111
$day = TDateTime('10-12-2005', 0);
echo $day.'<br>'; // prints 38637i only see the text if i comment every try / catch
what do i have wrong with the try / catch portion. is there extra functions needed for it to work? or is there something else i need to do?
Thanks for you help.