Should a business rule violation throw an exception?
相关问题
- how to call a C++ dll from C# windows application
- What does the LinkedAuthorizationFailed mean in Po
- Catch the same exception twice
- Create CFrameWnd gives first-chance exceptions--wh
- Creating exception classes for lot different error
相关文章
- JUnit continue to assert things after expected exc
- Do errors thrown within UncaughtExceptionHandler g
- nested try/except in Python
- How to handle translation of exception message?
- correct way to store an exception in a variable
- UnhandledException Event doesn't work?
- Any way in Visual Studio to not break on throwing
- C++ (Standard) Exceptions and Unicode
It depends on what the business rule is, IMO. I would venture to say "not usually" but I'd view it on a case-by-case basis. I don't think there is any one answer, as different business rules might warrant it while others might not.
Do you mean, for example, that a value is supposed to be in the range 0-99 but somehow ended up being 105?
If it's coming from the user it's a matter of validation. Whether it is handled using exceptions or not depends on the idioms of your language.
If it's coming from your data store then yes, it seems reasonable to throw an exception. It means you have bad data and you need to figure out how it got there and prevent it from happening again.