Things every Java developer must know about Exception handling
Je n’avais encore jamais reblogué, mais cet article est tellement bien écrit, il me semble être le candidat idéal pour un premier reblog !
Exceptions are one of the most misunderstood (and misused) features of the Java programming language. This article describes the absolute minimum every Java developer must know about exceptions. It assumes that the reader is somewhat familiar with Java.
Back in the heyday of the « C » programming language, it was customary to return values such as -1 or NULL from functions to indicate errors. You can easily see why this isn’t a great idea – developers had to check and track possible return values and their meanings: a return value of 2 might indicate « host is down » error in library A, whereas in library B, it could mean « illegal filename ».
Attempts were made to standardize error checking by expecting functions to set a global variable with a defined value.
James Gosling and other designers of the language felt that this approach would go against the design goals of Java. They wanted:
- a cleaner, robust and portable approach
- built in language support for error checking…
View original post 1 470 mots de plus