Setting output messages

About setting output messages

To support the full integration of program executables as tools, the geoprocessor has several methods for adding messages, which are then available to the user. Messages added to the geoprocessor are immediately returned to the application or program executing the tool. The following are the methods for adding various types of output messages:
Each of these methods takes a single string parameter. Once an error message is added, the geoprocessor immediately generates a system error that halts the execution of the tool.
The following code example copies a list of feature classes from one workspace to another. Error handling is used to catch any problems and return messages. Otherwise, messages of success are returned during execution. 
// Copy list of feature classes from one workspace to another.

IGpEnumList fcs = gp.listFeatureClasses("", "", "");
Copy copy = new Copy();
String fc =;
while (!"" .equals(fc)){
    gp.addMessage("Copying " + fc + " to file gdb");
    copy.setOutData("C:/temp/eric.gdb" + "/" + fc);
        gp.execute(copy, null);
    catch (Exception e){
        gp.addError("COPY FAILED! " + gp.getMessage(2));
    fc =;
There are times when you may want a script to return messages from a tool it has executed. Using an index parameter, the AddReturnMessage method returns a message from the geoprocessor's message array.