News for hackers. Stuff that matters.
Re:You’re better off using Exceptions by weberc2 on Monday February 03, 2020 @11:59AM (#22226080)
The problem is that these systems are built in a way in which the data access latter is throwing the exception even though it can’t reasonably know if the record is expected to exist or not. It can’t or shouldn’t know that this is an invalid program state. Specifically, if exceptions are being used properly, you should almost never need to use try/catch.
Re:You’re better off using Exceptions by seanmcdirmid on Monday February 03, 2020 @12:25PM (#22226379)
Those are poorly designed APIs then. That is like having a dictionary that throws when a key isn't found but doesn't have an API for determining if a key exists or not.
Re:You’re better off using Exceptions by appleiigs on Monday February 03, 2020 @12:40PM (#22226623)
Yes, poorly designed API, but we still have to handle them and the world is filled with them. So you can have a structure that works for the real world, or you can have an ideological structure the stubbornly insists that you should know better. "bad programmer! you should know if the key exists or fail".
Re:You’re better off using Exceptions by seanmcdirmid on Monday February 03, 2020 @01:01PM (#22226932)
Poorly designed APIs provide little evidence on exceptions being bad or not since the APIs themselves have big problems.
Re:You’re better off using Exceptions by weberc2 on Monday February 03, 2020 @08:59PM (#22231603)
This thread is discussing whether exceptions are bad for handling unexceptional events. We are arguing that APIs that throw exceptions for valid program states, such as a missing key for some user input, is an abuse of exceptions. There are lots of these APIs in the world and we find that objectionable. You seem to agree with all of that, but you also present yourself as disagreeing with us, and it’s not at all clear what you’re disagreeing with specifically? Are you just being contrarian for its own sake or are we misunderstanding each other?
Re:You’re better off using Exceptions by weberc2 on Monday February 03, 2020 @07:28PM (#22230990)
It’s a poorly designed API, full stop. It doesn’t matter whether or not it has an API to check existence, it’s not the dictionary’s job to know whether or not a missing key is a valid state in the broader program, and most often it is. Moreover, it’s insane to do a separate “if exists” check every time you need some resource. And the world is littered with these poorly designed APIs, as they are idiomatic in Python, JS, C#, and Java.