Skip to main content
21 events
when toggle format what by license comment
Jun 21, 2017 at 17:50 comment added T. Sar @AnotherDeveloper Why not? If the exceptions explodes, you know something went wrong. Check the type of exception, and them you do what you need to do. I wouldn't use EF for a database I can't make EF work properly on top of, but lacking that, exceptions are good enough.
Jun 21, 2017 at 17:14 comment added AnotherDeveloper @TSar In the context of the question, are you suggesting I simply attempt a delete, let the SQL Server return the conflict, let EF return that as an exception, and use that exception to control the logic of the application?
Jun 21, 2017 at 17:05 comment added T. Sar @AnotherDeveloper The same documentation suggests guidelines on how to implement your own and how to use them. Why those sections would even exists if exceptions were "bad, avoid at all costs"? Remember - guidelines are just rules-of-thumb, not programming laws.
Jun 21, 2017 at 17:03 comment added T. Sar @AnotherDeveloper "Consider" isn't "Do". The guideline says you should think about it, not blindly doing something without reason nor rhyme. You should weight the cost benefits, and, in your case, it points towards the exception instead of a long chain of reflection-based calls. Beware of Cargo Cult Programming.
Jun 21, 2017 at 16:52 comment added AnotherDeveloper @TSar To be more clear, this is an excerpt: "For conditions that are likely to occur but might trigger an exception, consider handling them in a way that will avoid the exception. For example, if you try to close a connection that is already closed, you'll get an InvalidOperationException. You can avoid that by using an if statement to check the connection state before trying to close it."
Jun 21, 2017 at 15:50 comment added AnotherDeveloper @Tsar docs.microsoft.com/en-us/dotnet/standard/exceptions/…
Jun 21, 2017 at 1:53 comment added T. Sar You didn't say anything that would put a valid constraint against exceptions. You put it as your personal preference, which isn't really a valid way to avoid a basic language construct. Variable names, patterns of choice.. those things are choices. Avoiding exceptions is like avoiding "ifs" - an artificial constraint with no real added value.
Jun 20, 2017 at 21:12 comment added AnotherDeveloper @TSar I understand the argument you are making, but I don't know if it applies to what I am describing. To fit into your analogy, it would be "how can i make my head hurt less when i bang it against a wall. As a constraint, it cannot be ensured it will not be banged against the wall" Then of course you get the person who ignores your constraint and says, "Stop banging your head against the wall". What if I'm a miner, or a construction worker? Maybe the answer to the question should be, "a helmet"
Jun 20, 2017 at 20:04 comment added T. Sar @AnotherDeveloper The problem isn't really the culture around here or there. When someone asks "how can I make my head hurt less when I bang it against a wall", we usually answer "stop banging your head against the wall". The arrogance comes from those that fail to recognize that their problem is hitting the wall with their head in the first place and instead keep asking for a solution for the wrong problem. We aren't winning any cookie points being arrogant. We aren't the ones needing help, too. So, when you come to somewhere asking for the experts' opinion, you should at least listen.
Apr 23, 2017 at 22:20 history tweeted twitter.com/StackSoftEng/status/856271562374336516
Apr 12, 2017 at 19:26 vote accept AnotherDeveloper
Mar 27, 2017 at 23:19 comment added AnotherDeveloper @joshp I totally get what you are saying. I have done this very thing in the past as well. But I have a problem with the culture here and at StackOverflow because a lot of members arrogantly assume the context of the question instead of just judging the question at it's face value. I've already explained I'm not interested in using exceptions.. What I do now is simply flag comments and answers that are not helpful. Robert Harvey is not interested in answering my question.
Mar 27, 2017 at 22:12 comment added joshp @AnotherDeveloper I agree w/ Robert Harvey and often use exceptions in this scenario with great results. Maybe you could avoid the inverse XY effect, where people answer a question you are not interested in by misleading us a bit more effectively. You could say "I'm working with an ancient legacy schema that has no referential integrity constraints and I'm not allowed to add any (Big Iron DBA Voodoo, don't ask) and I hope to use Entity Framework to find dependencies. Here is what I have tried. Here is what I don't like about it...Ahh as I type this I see your answer. That may help.
Mar 27, 2017 at 22:04 answer added AnotherDeveloper timeline score: 0
Mar 27, 2017 at 19:19 comment added Robert Harvey The other solution seems self-evident. What's unclear?
Mar 27, 2017 at 19:12 comment added AnotherDeveloper @RobertHarvey I specifically added the line about not wanting to use exceptions because I knew people would just tell me to check the exception. I already have that solution. I don't want to argue about the what my choices are, I want to see if anyone can solve the specific question I asked on the forum. I think I have made this clear by now.
Mar 27, 2017 at 19:04 comment added Robert Harvey It sounds like you're accessing a database, probably over a network. The exception is the cheapest part of this process. Measure, don't guess.
Mar 27, 2017 at 18:57 answer added Jon Raynor timeline score: 2
Mar 27, 2017 at 18:57 comment added AnotherDeveloper @RobertHarvey Basically, what I'm writing is a method named HasChildren and it either returns true or false. Coding for exceptions is going to limit what I can do with it, so it's not simply about style. Exceptions are expensive and I want to avoid it.
Mar 27, 2017 at 18:50 comment added Robert Harvey It's unclear from just your verbal description what your new code is going to look like. Why would it return true, for example; doesn't true usually signal success and not failure? This might be one of those cases where it's easier (and proper) to handle the exception instead of getting clever just to avoid them.
Mar 27, 2017 at 18:15 history asked AnotherDeveloper CC BY-SA 3.0