Raising Hell
We’ve put up with other people’s errors for long enough. It’s time to turn the tables and play the bad guy: Let’s raise some errors. When writing a function, erroneous things will happen that you’ll need to signal to your caller. Make sure you do—don’t silently swallow any failure. Even if you’re sure that the caller won’t know what to do in the face of the problem, it must remain informed. Don’t write code that lies and pretends to be doing something it’s not.
Which reporting mechanism should you use? It’s largely an architectural choice; obey the project conventions and the common language idioms. In languages with the facility, it is common to favor exceptions, but only use them if the rest of the project does. Java and C# really ...
Get Code Craft now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.