Linked Questions

109
votes
7answers
27k views

How to write a good exception message

I'm currently doing a code review and one of the things I'm noticing are the number of exceptions where the exception message just seems to reiterate where the exception occurred. e.g. throw new ...
28
votes
2answers
3k views

Who should read Exception.Message if at all?

When designing exceptions should I write messages that a user or a developer should understand? Who should actually be the reader of exception messages? I find exception messages aren't useful at all ...
22
votes
3answers
8k views

How should I provide additional information about an exception?

Everytime I need to provide additional information about an exception I wonder which way is actually the right way of doing this. For the sake of this question I wrote an example. Let's assume there ...
11
votes
5answers
2k views

How to design exceptions

I'm struggling with a very simple question: I'm now working on a server application, and I need to invent a hierarchy for the exceptions (some exceptions already exist, but a general framework is ...
1
vote
5answers
746 views

Avoiding exceptions for performance optimization

In our code base, I see a lot of code like this var error = ValidatePhoneNumber(userId, phoneNumber); //if validation fails, return error if(!string.IsNullOrEmpty(error)) { return error; } If I ...
2
votes
3answers
970 views

Benefit of throwing exceptions for null parameters

The codebase I work with has a certain pattern prevalent in all public methods, which goes like this: public void UpdateUser(User userArg) { Framework.NullCheck(userArg); var user = userDb....
3
votes
3answers
224 views

Extended usage of an exception

I'm in the process of building a routing system for learning purposes and have encountered an issue which I think is a bit in the grey area of best practices. Can you guys help me decide if this is ...
4
votes
1answer
255 views

Throwing an exception from within a constructor of an exception

As I was TDD-ing some code, it occurred to me that one of my typed exceptions could potentially throw a NullReferenceException while creating its error message. Here's the constructor for the typed ...
3
votes
1answer
611 views

Overflow Exception Checking Problem

Background I have to call a method that needs to return a signed integer (see code block below) after converting from an unsigned integer. The reason for this is that I have to do bit-wise math that ...
3
votes
2answers
176 views

What are common/best practices for frameworks handling standard third-party exceptions?

Amongst other things in my life, I'm writing a framework in PHP to manage a slew of common problems I come up against in every project I tackle. The framework is currently very data-centric, with the ...