Hi,
I'm trying to check the result of the ModelingExecuteHierarchyMapping function in APE but I'm struggeling....
I'm calling the function with a mapping, that does not exist using this code:
#define EngineVersion 5.0
#define RuntimeVersion 5.0
bool TEST()
@Description: "Mappings";
@Returns: "true";
{
string mm_line = "";
int mm_index = 0;
ModelingOperationResult map_result = ModelingExecuteHierarchyMapping("Logistik", "Unknown_Mapping_Name");
StringList mapping_message = ModelingOperationResultGetMessages(map_result);
// Check if successful
if (ModelingOperationResultIsSuccess(map_result))
{
NotifyInformation("Mapping successful");
}
else
{
NotifyInformation("Mapping not successful");
int mm_count = Count(mapping_message);
while (mm_index < mm_count) {
mm_line = GetElementByIndex(mapping_message, mm_index);
WriteLine (mm_line);
mm_index = mm_index + 1;
}
}
return true;
}
When running the process in APE-Editor the console window shows the expected error message:
Execute Process: TEST
Executing the process failed with an error. The returned message was: An error has occurred:
Calling function 'ModelingExecuteHierarchyMapping' failed with this message: Modeling Mapping Unknown_Mapping_Name not found.
However, the process crashes at this time and I have no chance to control the result and write the status in a table or do something else to pass the fail status back to the calling application.
Then I tried it with try/catch:
try{
ModelingOperationResult map_result = ModelingExecuteHierarchyMapping(applicationName, mappingName);
}
catch (errorMessage, errorCode) {
StringList mapping_message = ModelingOperationResultGetMessages(map_result);
// Check if successful...
Problem here: inside the catch the variable map_result is not declared.
How can I declare the map_result globally? I don't know how to initialise the variable...
Could anybody please provide a code snipped that shows how to check the result of a mapping, so that all cases like mapping does not exist at all, mapping returns error, mapping returns warnings, etc. can be controlled and the process itself does not crash.
Thanks in advance,
Ralf