5 ms·
is that really more work than: int res; try { res = Integer.parseInt( s ); } // if part catch ( NumberFormatException nfe ) { } // else part The words a
by lucastheisen 14y ago
is that really more work than:
int res;
try { res = Integer.parseInt( s ); } // if part
catch ( NumberFormatException nfe ) { } // else part
The words are different (try/catch instead of if/else), but still 2 blocks of code with similar syntax...
- MichaelGG 14y agoThe main reason for TryParse, AFAIK, is avoiding the massive expense of exceptions on the CLR. Another reason is composability. If you're checking several values together, returning a Maybe/Option is much more clear and usable.