4 ms·
Using an exception to signal a semantic error is only expensive if the language implementer has made that expensive. Technically, all the exception throw needs
by barrkel 10y ago
Using an exception to signal a semantic error is only expensive if the language implementer has made that expensive.
Technically, all the exception throw needs do is pop stack frames until it finds a handler. Getting a stack trace is optional, but keeping track of the return addresses (pushed by the CPU's call instruction) is sufficient to materialize that on demand. An array of integers isn't expensive either.
I don't believe transactional programs using exceptions for rollback is an anti-pattern. It's not the best pattern - a transactional language, with transactional data structures, is much harder to get wrong - but it's not worst, not by a long shot.
- johnwatson11218 10y agosorry - I didn't mean to indicate that using transactions to signal a roll back is an anit-pattern. I started out that comment listing good things I had see exceptions used for. Then that example of the userNameInUse exception came to mind. I realize my choice of words made that less than clear.