C
C#3y ago
demndev

The best place to handle domain exceptions in an MVC app?

13 Replies
JakenVeina
JakenVeina3y ago
without any further context, I'm gonna have to say "don't use exceptions for normal control flow"
demndev
demndevOP3y ago
what to use instead? result objects?
Anton
Anton3y ago
you can catch them in a middleware
demndev
demndevOP3y ago
and do all checks about all type of exceptions?
Anton
Anton3y ago
probably make them inherit from a DomainException of sorts, so you can generalize it somewhat but yeah that's considered a bad pattern, because it becomes harder to track the logic flow
demndev
demndevOP3y ago
what about to make an exception filter for each controller action?
Anton
Anton3y ago
I wish c# had some syntax for result types to make them less verbose
demndev
demndevOP3y ago
yes…
Anton
Anton3y ago
yeah, I think that's actually better because you can use the MVC action result system then
demndev
demndevOP3y ago
good. probably I will use this approach
JakenVeina
JakenVeina3y ago
probably a good bet but it all depends on context
demndev
demndevOP3y ago
for what kind of context result objects will be better than exceptions?
JakenVeina
JakenVeina3y ago
most stuff in web land, for example

Did you find this page helpful?