Anyway, while working on a major refactoring like this one, you run into many, many small code issues. Clearly. the one I mostly run into is that a lot of code is not written against the interfaces yet. However, I just ran into another bit of code that can be improved.
Set the cause Exception when throwing a CDKException
This is the particular bit of code I ran into:
try {
molecule = (IMolecule) container.clone();
} catch (CloneNotSupportedException e) {
throw new CDKException(
"Error occured during clone " + e
)
}
However, there are two small improvements that can be applied to this code. The first is that the the error message passed to the CDKException constructor can reuse the message of the cause Exception. The second improvement is that we can actually pass the cause exception is cause to the CDKException. Therefore, the CDKException can be constructed as (also fixing the typo :):new CDKException( "Error occurred during clone " + e.getMessage(), e );Oh, and, of course, CDK code should use variables of at least three characters. Now, the original CDKException construction was on one line, in total having four points of improvement :)
No comments:
Post a Comment