Exposed vs modern exceptions (Java SE 7)

Question

What are the advantages and disadvantages of exceptions in a context with nested exceptions?

Why do i care

As a developer who doesn't have a background or know Java background, I came across a possible opportunity to update open source exception handling, but I want to make sure that the change I will make is useful.

The project in question is ddlutils . It currently uses org.apache.commons.lang.exception, which states:

"Provides Nested Exception functionality for JDK 1.4 for those that were in previous versions of Java."

The current version of Commons Lang (3.1 at the time of writing) uses org.apache.commons.lang3.exception, which states:

"Contains the concept of an exception with a context, that is, such an exception will contain a map with keys and values. This provides an easy way to convey valuable state information at an exceptional time in a useful form to the calling process."

+4
source share
1 answer

When discussing this, you should know JDK1.4, released about 10 years ago. He invented an exception chain, which simply means that you have a constructor that accepts the cause of the exception. And then a nice complex stack trace is printed for all this stuff. Prior to JDK1.4, there were many such implementations in JDK, and they were combined into a single consistent solution. Now, what has been done is to provide some base simlar classes to get this idea for older JDKs. However, since many events have occurred:

  • JDK 1.3 has ended the maintenance period.
  • The period of public support for JDK 1.4 has ended.
  • JDK 5 public service period has ended.
  • and now the JDK 6 public maintenance period is nearing completion.

Thus, no one else is interested in versions of previous versions of JDK 1.4.

Now, on the other hand, this exception to the contextual thing has nothing to do with any version of the JDK. These are again the base classes for exceptions, but it has a Map in which to put things. This is usually implemented by special types of exceptions with additional fields. It is a safe type, beautiful and clean. Having a card on each exception means you never know what will be on that card. I cannot think of any benefit that this provides. So, if you don't have a really great plan to use it, I would not recommend it.

+2
source

All Articles