Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive


Ben Taylor

That's what I call Just In Time Documentation. Or Context Sensitive Help.


DRY violation?


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."

Rob Ashton

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.

Neil Barnwell

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?

Ayende Rahien


Yes, thanks, fixed.

Ayende Rahien


I learned that style from Castle, where it has been successful for over half a decade.

Neil Barnwell


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.

Ayende Rahien


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

Ayende Rahien


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.

Geert Baeyaert

You probably don't want to increment numberOfRequests when you throw the exception.

Demis Bellot

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.

Darren Kopp

And then that throws an OutOfMemoryException XD

Dan Finch

This is a good thing

Diego Mijelshon

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)

Kevin Kuebler

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".

Steve Py

+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.

Ayende Rahien


The problem isn't temporary, if you make another request, it should be blocked as well.

Steve Py

Ah, so it's total requests, not current requests. I.C.

Jeff Tucker

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

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats