jsp - Error checking in java while converting a string to a double -


i tryin convert string array double array, depending on weather station chosen database - weather stations have no data, whole string array filled nulls(12 of them in fact) obviosly if 1 of them stations chosen exception. realy have no time write lot of code work around it, since have submit work soon... there solution catch , display error message user insted of lines , lines explaining error? thanks!

here loop convert string array double array

for(int = 0; i<12; i++) {    avmaxtempoptimised[i] = double.parsedouble(avmaxtempsplit[i]); avmintempoptimised[i] = double.parsedouble(avmintempsplit[i]); meantempoptimised[i] = double.parsedouble(meantempsplit[i]); highesttempoptimised[i] = double.parsedouble(highesttempsplit[i]); lowesttempoptimised[i] = double.parsedouble(lowesttempsplit[i]); maxwindoptimised[i] = double.parsedouble(maxwindsplit[i]); totalrainfalloptimised[i] = double.parsedouble(totalrainfallsplit[i]); maxdayrainfalloptimised[i] = double.parsedouble(maxdayrainfallsplit[i]); raindaysoptimised[i] = double.parsedouble(raindayssplit[i]); totalsunshineoptimised[i] = double.parsedouble(totalsunshinesplit[i]); mostsunshinedayoptimised[i] = double.parsedouble(mostsunshinedaysplit[i]);  avmaxtemp2optimised[i] = double.parsedouble(avmaxtemp2split[i]); avmintemp2optimised[i] = double.parsedouble(avmintemp2split[i]); meantemp2optimised[i] = double.parsedouble(meantemp2split[i]); highesttemp2optimised[i] = double.parsedouble(highesttemp2split[i]); lowesttemp2optimised[i] = double.parsedouble(lowesttemp2split[i]); maxwind2optimised[i] = double.parsedouble(maxwind2split[i]); totalrainfall2optimised[i] = double.parsedouble(totalrainfall2split[i]); maxdayrainfall2optimised[i] = double.parsedouble(maxdayrainfall2split[i]); raindays2optimised[i] = double.parsedouble(raindays2split[i]); totalsunshine2optimised[i] = double.parsedouble(totalsunshine2split[i]); mostsunshineday2optimised[i] = double.parsedouble(mostsunshineday2split[i]); } 

if try/catch outside loop, you'll stop processing rest of loop. try/catch inside loop closer, long don't mind unassigned values left in array. might best, changing optimized arrays type double[]:

for(int = 0; i<12; i++) {    avmaxtempoptimised[i] = safedouble(avmaxtempsplit[i]); avmintempoptimised[i] = safedouble(avmintempsplit[i]); meantempoptimised[i] = safedouble(meantempsplit[i]); highesttempoptimised[i] = safedouble(highesttempsplit[i]); lowesttempoptimised[i] = safedouble(lowesttempsplit[i]); maxwindoptimised[i] = safedouble(maxwindsplit[i]); totalrainfalloptimised[i] = safedouble(totalrainfallsplit[i]); maxdayrainfalloptimised[i] = safedouble(maxdayrainfallsplit[i]); raindaysoptimised[i] = safedouble(raindayssplit[i]); totalsunshineoptimised[i] = safedouble(totalsunshinesplit[i]); mostsunshinedayoptimised[i] = safedouble(mostsunshinedaysplit[i]);  avmaxtemp2optimised[i] = safedouble(avmaxtemp2split[i]); avmintemp2optimised[i] = safedouble(avmintemp2split[i]); meantemp2optimised[i] = safedouble(meantemp2split[i]); highesttemp2optimised[i] = safedouble(highesttemp2split[i]); lowesttemp2optimised[i] = safedouble(lowesttemp2split[i]); maxwind2optimised[i] = safedouble(maxwind2split[i]); totalrainfall2optimised[i] = safedouble(totalrainfall2split[i]); maxdayrainfall2optimised[i] = safedouble(maxdayrainfall2split[i]); raindays2optimised[i] = safedouble(raindays2split[i]); totalsunshine2optimised[i] = safedouble(totalsunshine2split[i]); mostsunshineday2optimised[i] = safedouble(mostsunshineday2split[i]); }   ...  safedouble( string str){ return str== null ? null : double.parsedouble(str); } 

add in quick null checks read optimized arrays , you're golden.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -