string int java - approaching bad data, need prevaricate exceptions


seeing java doesn't have nullable types, nor does have tryparse(),
how hoop quarrel validation but throwing an exceptions?



the common way:



string userdata = /*value gui*/
int val;
try
{
val = integer.parseint(userdata);
}
catch (numberformatexception nfe)
{
// bad information - set sentinel
val = integer.min_value;
}


i regex check it's parseable, nonetheless seems lot over well.



what's best use doing situation?



edit: rationale:
there's lot pronounce difference handling, whole opinion exceptions should used astonishing scenarios only. however, i cruise bad user quarrel expected, rare. yes, unequivocally an educational point.



further edits:



some answers denote accurately wrong so. replace doubt being asked, answer another doubt zero it. doubt isn't seeking transition between layers. doubt isn't seeking relapse array un-parseable. know, val = integer.min_value; accurately right choice concentration totally context giveaway formula dash take from.



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?