![]() ![]() Why not just use them instead of exceptions?Īssert and raise appear to function similarly. Rule of thumb: Whenever you have information about a specific, replicable edge case, use it.īut why bother with exceptions at all? We use asserts in testing all the time, and they do a great job. We could definitely refactor this to make the response codes an enum or a similarly expressive format, but there’s no confusion in this code that whatever those random response codes are, they mean that we don’t have 2-factor authentication enabled and we need to configure this setting in our example provider to get this to work. Some providers just want to watch the whole world burn. Take the following example.Ĭonfusing API responses being translated into a clear exception They also help people understand what’s going on. That’s right - exceptions aren’t just for debugging or handling. Long names no longer slow down development, but they do significantly benefit anyone debugging or reading the code. These days, I’ll be lucky to type more than two before my IDE realises what I’m trying to do and finishes the job. But also, I had to type all three of those characters in num. And, yes, I used to name things int num or char* s1. I learnt to code in C, using Vim, with no autocomplete. ![]() Me before Atom, Visual Studio, and IntelliJ, in the land of Vi and Nano, where variable name length actually affected developer productivity. You know where to go to find the issue, and you know exactly what to try catch if you’re OK with attempting to delete a user that’s already been deleted. OK, the last one could probably be renamed to CannotDeleteNonExistentUser, sure, but the point is they’re clear. These exceptions provide the most valuable function exceptionally well - they’re specific, informative, and to the point. These names look challenging to read and are long to type, but are they really so scary? CannotDeleteUserAccountThatDoesntExistExceptionĮxceptions, exceptions, exceptions everywhere.JavascriptMillisecondTimeFormatBufferOverflowException. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |