I'm working on a set of C# GP tools for use both in Desktop and Server 10.1.
The only soup-to-nuts treatment of writing geoprocessing tools in .NET appears to be Building a custom geoprocessing function tool. It does not cover what to do to handle exceptions.
I see a few possibilities and want feedback.
- In my tool's Execute() method, I can put my code in a try block, and in the catch I can augment the Messages by IGPMessages message.AddError(errorcode, errormessage).
- I can include among my tool's output parameters an error code parameter and an error message parameter. In the Execute() method's catch block, I populate these parameters if an exception occurs. Then they are available to the client in its Result object.
- do both.
(1) While this seems sensible for Desktop use, it seems to suffer a problem if in Server the GP service is configured not to return messages to the client.
(2) seems to suffer a problem in that I don't know of other tools that use this approach.
I want to make sure that the tool works correctly with the ArcGIS Silverlight API Geoprocessor task, which raises a Failed event if a task fails. What do I implement in .NET to make the task 'fail' correctly and gracefully?