Ayende @ Rahien

Refunds available at head office

And now this is what I call error handling

image

Comments

Ben Taylor
05/25/2010 09:20 AM by
Ben Taylor

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

grega_g
05/25/2010 09:21 AM by
grega_g

DRY violation?

Huseyin Tufekcilerli
05/25/2010 09:24 AM by
Huseyin Tufekcilerli

This guy seriously needs to learn about StringResources

Andrew
05/25/2010 09:41 AM by
Andrew

Shouldn't it be numberOfRequests++ (a max of 1 query should mean 1 query is OK, but 2 is not) :P

armoured.frog
05/25/2010 09:56 AM by
armoured.frog

don't mean to nitpick..but did you mean "result in a more responsive application."

Rob Ashton
05/25/2010 10:14 AM by
Rob Ashton

I quite like the concept of a more responsible application.

Dennis
05/25/2010 10:36 AM by
Dennis

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
05/25/2010 10:45 AM by
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).

Aikin
05/25/2010 11:13 AM by
Aikin

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
05/25/2010 11:22 AM by
Ayende Rahien

armoured.frog,

Yes, thanks, fixed.

Ayende Rahien
05/25/2010 11:23 AM by
Ayende Rahien

Neil,

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

Neil Barnwell
05/25/2010 11:36 AM by
Neil Barnwell

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? :)

Rafal
05/25/2010 11:41 AM by
Rafal

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
05/25/2010 11:53 AM by
Ayende Rahien

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

Ayende Rahien
05/25/2010 11:53 AM by
Ayende Rahien

Rafal,

No one read the logs.

Peter
05/25/2010 11:59 AM by
Peter

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.

tobi
05/25/2010 12:05 PM by
tobi

Just great. I wish it was always like this. Both the message and the "warning" exception that you have to explicitly disable.

Geert Baeyaert
05/25/2010 12:27 PM by
Geert Baeyaert

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

Demis Bellot
05/25/2010 02:42 PM by
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
05/25/2010 03:38 PM by
Darren Kopp

And then that throws an OutOfMemoryException XD

Dan Finch
05/25/2010 04:36 PM by
Dan Finch

This is a good thing

Diego Mijelshon
05/25/2010 04:37 PM by
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
05/25/2010 05:25 PM by
Kevin Kuebler

throw new YerDoinItWrongException();

;-)

Isaac
05/25/2010 08:35 PM by
Isaac

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
05/25/2010 10:33 PM by
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
05/25/2010 11:22 PM by
Ayende Rahien

Steve,

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

Steve Py
05/25/2010 11:50 PM by
Steve Py

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

Jeff Tucker
05/26/2010 06:03 PM by
Jeff Tucker

What about "throw new BadCodingPracticeException" instead?

Troy
05/27/2010 01:04 AM by
Troy

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.

Comments have been closed on this topic.