FUTURE POSTS
- Partial writes, IO_Uring and safety - about one day from now
- Configuration values & Escape hatches - 5 days from now
- What happens when a sparse file allocation fails? - 7 days from now
- NTFS has an emergency stash of disk space - 9 days from now
- Challenge: Giving file system developer ulcer - 12 days from now
And 4 more posts are pending...
There are posts all the way to Feb 17, 2025
Comments
That's what I call Just In Time Documentation. Or Context Sensitive Help.
DRY violation?
This guy seriously needs to learn about StringResources
Shouldn't it be numberOfRequests++ (a max of 1 query should mean 1 query is OK, but 2 is not) :P
don't mean to nitpick..but did you mean "result in a more responsive application."
I quite like the concept of a more responsible application.
It should throw a MaximumNumberOfRequestsException instead. You aren't doing an Invalid operation, you have just passed the useful limit.
And why is it I would always have to know ahead of time how many queries I am going to be executing. This will be an absolute nightmare for an application 10 years down the road where the source code is long gone.
I like the idea of error messages that actually say what the problem is, and even tell you what to do, but I'm torn. I'm torn because the message is effectively a kind of magic string that has details like configuration item names etc, which is going to go out of date if you refactor in the future (say for example you decide to write a clever algorithm that automatically works out the max requests value based on historical usage to determine extraordinary behaviour).
Hei guys! That is the ESSENTIAL! The idea. No more.
Try to do the same proper way (resources, exception helpers, ...).
And when you finish just compare your (COOL and PROPER) code with the one provided. Is it EASY to understand what you did want to explain?
armoured.frog,
Yes, thanks, fixed.
Neil,
I learned that style from Castle, where it has been successful for over half a decade.
Ayende,
Yeah, I have to admit I've always wanted to do it, but always changed my mind at the last minute because of reason I mentioned. It's kind've like documentation - it's hard to keep it up to date and in-sync with the code.
Do you have any tips for keeping these kind of messages relevant over time, when there are many of them? Surely even you can't just remember where they all are and update them when something changes? :)
Nice error message, but in this case I'd rather warn the administrator and continue servicing requests without scarying application users and suggesting the application is broken.
Neil,
Those type of things don't change often.
And you basically need to remember those.
Nothing really fancy or high tech. The advantage that you can get from that is huge
Rafal,
No one read the logs.
I like these kind of error messages, because they help a developer much more than general messages (NullReferenceException anyone?).
@Neil: if you use ReSharper to rename methods, it will search in strings also, so that shouldn't be a problem.
Oh, also some nitpicking: ... Raven provideS facilities ...
Nice work, can't wait to try out Raven.
Just great. I wish it was always like this. Both the message and the "warning" exception that you have to explicitly disable.
You probably don't want to increment numberOfRequests when you throw the exception.
What does it want me to do?
I think long error messages like this would break the rendering of UI error/warnings on the client.
I prefer an error code and a 'succinct error message' and a url for a more detailed explanation where I could explore other comments and solutions from people who have also encountered this error. If you don't provide a url yourself then you should at least supply an error code so its googable.
IMHO motivations behind why you've chosen to throw an error have no place in an Exception message (that's what documentation is for) - it's long enough as it is.
And then that throws an OutOfMemoryException XD
@Dennis, you can override the default if you want to. but see groups.google.com/.../d0cfb634b89a75e8 for a discussion of why you might not want to.
This is a good thing
I like the idea.
One of the things I LOVE about NHibernate, for example, is that the error messages usually give you enough information to know what's wrong and how to fix it without having to open a debugger every time.
The only change I'd do would be introducing a MaximumNumberOfRequestsException like Dennis suggested (whether or not to derive it from InvalidOperationException is up to you)
throw new YerDoinItWrongException();
;-)
Conceptually great, but the writing could use some help. "It is advisable that you'll look into reducing" should just be "Consider reducing".
+1 to Geert !
Incrementing then throwing the exception is a bad idea. If the exception is caught and handled (I.e. make the requester wait, etc.) then you've increased the count without using a request; Poluting your request count with false requests, hindering performance when "real" requests are let go.
Your intent might be that during development developers would receive this exception and re-factor their design. Real-world though is that stuff like this will come up in UAT/Production and bug fixes will effectively be jury-rigs. A caught and handled exception in this case is now a behaviour bug. It's fine to provide details within the exception, if something needs to be told to a user they should be presenting an application-meaningful exception message anyways.
Steve,
The problem isn't temporary, if you make another request, it should be blocked as well.
Ah, so it's total requests, not current requests. I.C.
What about "throw new BadCodingPracticeException" instead?
This is the result of your years of support.
I don't think you should put training or enforce good practice through error messages. But, neither can I say I wouldn't do it. At the end of the day, losing some number of phone calls to your tech support is money in your pocket--both from less support AND from the bad press: "This stupid Raven thing runs so slow . . ." yada, yada, yada.
I'd search hard for a more appropriate vehicle for the message. But, maybe there isn't one that would be as effective.
Comment preview