You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
-
1I don't see why you can't leverage the existence of AggregateException if needed. For a CRUD application a single exception may be enough, though.Machado– Machado2017-05-16 17:23:28 +00:00Commented May 16, 2017 at 17:23
-
@Machado: This would make sense if you expect valid input, but perform a precondition check to be defensive. But if there is a specific method for validating user input, then it shouldn't throw an exception if there is validation errors, since this a legitimate outcome. Exceptions should IMHO only be for cases where a method is prevented from doing its designated job, which is not really the case here.JacquesB– JacquesB2017-05-16 17:32:16 +00:00Commented May 16, 2017 at 17:32
-
while I agree with you on the principle, I have some concerns on the practical use. Having a side validation method may be idiomatic on the API, but it's also a 2-step operation that requires the user of your code to read the documentation before trying it, in order to learn "the protocol". While just shoving things to the service and letting it figure out what to do and returning an error on a single step looks messy, but allows the programmer to learn by exploring your code instead of reading some lost wiki somewhere.Machado– Machado2017-05-16 17:52:21 +00:00Commented May 16, 2017 at 17:52
-
@Machado: If you want an API to be discoverable, exceptions are actually the worse choice since they are not indicated in the method signature (in .net) but are only discovered if you happen to trigger one...or read the documentation.JacquesB– JacquesB2017-05-16 18:05:38 +00:00Commented May 16, 2017 at 18:05
-
Yes, you're right. And that's the point. Explore the code and learn as you go. That would be exactly the same scenario with 2-step validation, without the need of the extra if. The 2-step validation requires you to learn the protocol, which you'll do by either triggering an exception because you didn't validate before calling or by reading documentation. Why not just embrace the exception in this case and reduce the complexity of your code since you'll still have the obligation to catch a exception ?Machado– Machado2017-05-16 18:16:35 +00:00Commented May 16, 2017 at 18:16
|
Show 4 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
-
create code fences with backticks ` or tildes ~
```
like so
``` -
add language identifier to highlight code
```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible)
<https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-cs