admin@glassfish.java.net

exiting decorator when throwing exception

From: Carla Mott <carla.mott_at_oracle.com>
Date: Fri, 17 Sep 2010 06:57:44 -0700

Hi,

I have a question about exiting a decorator when you find an error while
updating a config element. Specifically when I have to work within a
transaction. If I find an error and want to terminate processing
(return) I thought I had to throw an exception to return. When I do
that it seems that I get the error message twice. What is the proper
way to exit and what should the exception message be?

code below throws an exception but prints the message twice.

my decorator:
               
                if (instanceName != null) {
                    final String msg = localStrings.getLocalString(
                            "Node.referencedByInstance",
                            "Node {0} referenced in server instance(s):
{1}. Remove instances before removing node."
                            ,child.getName() ,instanceName );
                            throw new TransactionFailure(msg);
                }

            }

            nodeList.remove(child);

ends up GenericDeleteCommand:

       } catch(TransactionFailure e) {
            String msg =
localStrings.getLocalString(GenericCrudCommand.class,
                    "GenericDeleteCommand.transaction_exception",
                    "Exception while deleting the configuration {0} :{1}",
                    child.typeName(), e.getMessage());
            result.failure(logger, msg, e);
        }