• Post Reply Bookmark Topic Watch Topic
  • New Topic

New Resource about error messages.  RSS feed

 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stackify have recently produced a list of error messages for Java® programmers. The first twenty are compile‑time errors and the remaining thirty are runtime errors (exceptions). Some of those exceptions (e.g. bad magic number) look like the sort of corruption users of this forum probably wouldn't encounter. Others are the sort of thing they would see daily.
That list looks helpful. Each error has a description and an example and a link to a forum with more explanation. Of course the CodeRanch links are the best

Thanks to Stackify for what looks like a useful resource. Anybody got any error messages they would like to add? Or more situations?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest an addition: A NoSuchElementException is thrown by a Scanner pointing to System.in if System.in is closed. Searching this forum will reveal several discussions about closing System.in.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another addition. If you mistakenly write = instead of ==, this sort of thing happens:-OK Compiler error, which is hard for beginners to understand: Expected boolean found int. Notice how Java® scores over C/C++; having a separate boolean type, it doesn't use ints for true and false, so a C/C++ user would never have realised there is an error. At least not until much later, when there might have been disastrous wrong results.
If you try it with booleans, you get a different problem:-Ouch! Horrible code style in line 1. It sh‍ould read if (!b) ...You now have two errors for the price of one in line 1.
 
Liutauras Vilda
Sheriff
Posts: 4914
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are also logical errors, which are far more worse than compile or run-time errors.

Newcomers to the field often omit curly braces. Below you'll see an example, actually few.

Let's assume shipping charge to USA is 5.00, if Hawaii state - a bit more expensive, 10.00, if foreign country, 20.00. Example:

To remember: always use curly brackets {} to avoid the dangling "else" problem, as in this case "else" belongs to inner if, regardless of indentation.

So, the same example with curly brackets looks like this:

And the original idea was to have like this:
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately that sort of error doesn't produce any error messages, so it is probably outwith the scope of the Stackify webpage.
Errors which don't produce any error messages nor exceptions are more insidious and more dangerous because you don't find out about them until there are incorrect results. There is one sort of error even worse: that which produces no error messages, no exceptions, and sometimes the “correct” result.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!