3 ms·
If exceptions were free then yes, but there's not really any language/platform where that's the case. It'd instead be the reverse - Parse() calls TryParse() and
by kllrnohj 7y ago
If exceptions were free then yes, but there's not really any language/platform where that's the case. It'd instead be the reverse - Parse() calls TryParse() and throws an exception on false.
- Mikhail_Edoshin 7y agoA reverse approach would lose exception details; you cannot recover what exactly happened from a mere boolean and you may need it. It may not be possible to make exceptions totally free, but the rest of the language may be slow enough so they won't stick out :) Example: Python.
- ncmncm 7y agoTypically "try_parse" returns more than a bool on failure. What it does return is then wrapped and thrown.