| 747 | == Exception Handling == |
| 748 | |
| 749 | MapGuide employs a series of macros to simplify exception handling, propagation and stack trace recording. The macros are explained below: |
| 750 | |
| 751 | * MG_TRY() - Denotes the start of a try/catch block. Also declares a local variable {{{mgException}}} of type {{{Ptr<MgException>}}}. If any exception is caught, it will be assigned to this variable. |
| 752 | * MG_CATCH(methodName) - Denotes the end of a try/catch block. This macro defines catch blocks for common exception types ({{{MgException}}}, {{{std::exception}}} and {{{...}}}) and will append the current method name to the exception's call stack for any caught {{{MgExceptions}}}. You can do additional processing on the caught exception through the {{{mgException}}} local variable |
| 753 | * MG_THROW() - Re-throws the caught exception. In order the preserve stack trace information on {{{MgException}}} objects, you have to re-throw caught exceptions, which this macro will do. |
| 754 | * MG_CATCH_AND_THROW() - Is a combination of MG_CATCH() followed by MG_THROW(). Generally used when you don't need to do any custom processing on the caught {{{MgException}}} and generally just used to record the current method on the stack trace before throwing it back up. |
| 755 | |
| 756 | Each service API has service-specific variations of the above macros to do service-specific exception processing. It is generally advised to use these service-specific variations when dealing with code for that particular service (eg. Use MG_FEATURE_SERVICE_TRY(), MG_FEATURE_SERVICE_CATCH(), etc when working inside Feature Service code) |
| 757 | |
| 758 | Avoid the use of raw try/catch statements where possible, especially if you expect to catch exceptions of type {{{MgException}}}. |
| 759 | |