try catch in javascript? [SOLVED]
Posted: Mon Oct 24, 2005 1:03 pm
Basically, I'm trying to make a Half-Life calculator. I'm converting it from C++ to javascript. This is my code so far...
The try catch part does not work. If i comment out the try/catch parts. then it wont work correctly. but if they aren't commented out, then no other javascript works. I'm guessing I'm using them incorrectly, but I can't find anything of how to use it in javascript.
Any help on what I should do is much appreaciated. Thank you for any input.
edit: misuse of java inplace of javascript...
sorry for any misunderstanding
Code: Select all
function DecayIt(origActivity, halfLife, origTime, origDate, currTime, currDate)
{
origActivity = parseFloat(origActivity);
halfLife = parseFloat(halfLife);
origTime = TDateTime(origTime);
origDate = TDateTime(origDate);
currTime = TDateTime(currTime);
currDate = TDateTime(currDate);
var currentActivity = 0.0;
var nCurrentActivity = 0.0;
var fExp = 0.0;
var fExp1 = 0.0;
var fMult = 0.0;
currentActivity = parseFloat(currentActivity);
nCurrentActivity = parseFloat(nCurrentActivity);
fExp = parseFloat(fExp);
fExp1 = parseFloat(fExp1);
fMult = parseFloat(fMult);
var elapsedTime;
elapsedTime = currTime + currDate;
if(parseFloat(elapsedTime) == 0.0)
{
return 0.0;
}
elapsedTime = (currTime + currDate) - (origTime + origDate);
elapsedTime = parseFloat(elapsedTime) * 24.0;
if (parseFloat(elapsedTime) != 0.0) {
elapsedTime = parseFloat(StrToFloat(FormatFloat(elapsedTime)));
} else {
return origActivity;
}
if (halfLife > 0)
{
fMult = -0.693 * elapsedTime;
try
{
fExp = fMult / halfLife;
if (fExp >= 11356.50)
{
fExp1 = 0.0;
}
else
{
try { fExp1 = expl(fExp); } catch (...) { fExp1 = 0.0; }
}
nCurrentActivity = origActivity * fExp1;
}
catch(...)
{
nCurrentActivity = 0.0;
}
}
else
nCurrentActivity = 0.0;
currentActivity = parseFloat(nCurrentActivity);
try
{
if (currentActivity == 0)
currentActivity = 0.0;
}
catch (...)
{
currentActivity = 0.0;
}
return(currentActivity);
}Any help on what I should do is much appreaciated. Thank you for any input.
edit: misuse of java inplace of javascript...
sorry about that, i did google for javascript by the wayd11wtq wrote:Not sure on how to use try/catch in JS but on a side-note: JavaScript is not Java... the two are unrelated and entirely separate. If you have been googling for try/catch in java you wont find javascript realted stuff