Is having a return statement just to satisfy syntax bad practice?

A clearer way without an extra return statement is as follows. I wouldn’t catch CloneNotSupportedException either, but let it go to the caller.

if (a != null) {
    try {
        return a.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
}
throw new TotallyFooException();

It’s almost always possible to fiddle with the order to end up with a more straight-forward syntax than what you initially have.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)