2 ms·
Catch an exception of something that isn't exceptional? isn't that the anti-case for exception handling? I don't get why strict restructuring is a bad thing...
by Volpe 15y ago
Catch an exception of something that isn't exceptional? isn't that the anti-case for exception handling?
I don't get why strict restructuring is a bad thing... as long as it's consistant, it's just a nuance of the language.
Am I missing side effect of this? What are potential pit-falls of this pattern?
- ajuc 15y agoI was arguing that non-strict destructuring is bad, so this code IMHO should throw exception: a,b,c=[1,2,3,4] The reason for this is - if you assume array has 3 elements, but it has more, your code will silently ignore the rest. You'll have to write your assertion every time you destructure, to be sure that destructuring don't ignore data. The exceptional case IMHO is when you need to ignore data, and so code for this case should be uglier, not the other way around. You are right that catching exception for regular code path isn't the best way, but at least programmer intention is clear then. You could also do a,b,c = list.slice(0,3); which copies the array, but at least it's clear what it assumes about the array. And it can be easily modified to get last 3 values, or 3 values from the middle of list. So no need for 2 idioms depending on which items you want to get from the array.