What style do you use for exception reporting?

When writing code that throws an exception, which I asked about here , I came to the end of my post and settled on punctuation. I realized that almost every exception message I've ever thrown may have! somewhere.

throw new InvalidOperationException("I'm not configured correctly!");
throw new ArgumentNullException("You passed a null!");
throw new StupidUserException("You can't divide by 0!  What the hell were you THINKING???  DUMMY!!!!!");

What tone do you take when writing exception messages? When you look through the logs, you find that a certain message style really helps more than another?

+5
source share
9 answers

. , .

, Java , , . , " ", . , , , (, , , ..).

, , :

throw new IndexOutOfBoundsException("offset < 0: " + off);
+4

. , , .

, , - , - , . , , .

+6

, , . , , , - , .

(UI ), , () .

+5

, , , .

" , , ?" "- . , , , , - . , ".

+3

, (.. ArgumentNullException, , ).

, , .

+2

. , , " !" " , ".;)

, , . , , . , :

throw new MagicalException(getText("magical.exception.text"));

( ) . .

, . -, - .

+2

:

  • , , .
  • , .
  • . , .
  • , , .
  • , .

:

  • , .

:

Error 203 (Timeout) in commit.c line 42:
Unable to save salary data for user 'Linus' to database at '10.10.1.21'
after 1500ms.  Verify database address and login credentials.

, , , , . , , .

+2

, , . . file_not_found " ". , ; , . , , .

+1

, , , . , , .

+1

All Articles