A Trying Block
by in CodeSOD on 2025-05-22Mark sends us a very simple Java function which has the job of parsing an integer from a string. Now, you might say, "But Java has a built in for that, Integer.parseInt
," and have I got good news for you: they actually used it. It's just everything else they did wrong.
private int makeInteger(String s)
{
int i=0;
try
{
Integer.parseInt(s);
}
catch (NumberFormatException e)
{
i=0;
return i;
}
i=Integer.parseInt(s);
return i;
}