Survey Tabulation > Extending UNICOM Intelligence Reporter > Creating an export component > Handling errors
 
Handling errors
The code that you must implement to handle error conditions that arise during execution varies depending on whether your export component uses C++, VBScript or JScript as its implementation language.
There are examples of error reporting in the files that are generated by the Export Wizard. Refer to these examples to see how to report errors in the export code that you add.
C++ export projects
If you chose to create a C++/COM export component, the code that performs the export is written in the Export.cpp file, and error reporting should be included in that code. For example, let's look at the error reporting in the GetDestination object code. The following section handles saving the exported file when a file of the same name already exists.
// Export file already exists
if (IsInteractive())
{
CString strTitle;
strTitle.LoadString(IDS_MB_EXPORT_TITLE);
CDMFormat strMessage(0, E_FAIL);

if (_taccess(strPath, 2) == -1) {
// We can't overwrite the existing file
strMessage.Format(IDS_MB_FILE_READONLY, (LPCTSTR) strFileName);
::MessageBox(NULL, strMessage, strTitle, MB_OK | MB_ICONEXCLAMATION);
return S_FALSE; // not writing output file
}

strMessage.Format(IDS_MB_FILE_EXISTS, (LPCTSTR) strFileName);
if (::MessageBox(NULL, strMessage, strTitle, MB_YESNO | MB_ICONQUESTION) == IDNO) {
// User chose not to overwrite
return S_FALSE; // not writing output file
}
}
else // not interactive
{
if (!OverwriteOutput()) {
// We're not instructed to overwrite the existing file
CDMFormat errMsg(0, E_FAIL);
errMsg.Format(IDS_ERR_FILE_EXISTS, (LPCTSTR) strFileName);
return ReportError(errMsg, false);
}
if (_taccess(strPath, 2) == -1) {
// We can't overwrite the existing file
CDMFormat errMsg(0, E_FAIL);
errMsg.Format(IDS_ERR_FILE_READONLY, (LPCTSTR) strFileName);
return ReportError(errMsg, false);
}
}
The CDMFormat class is a Case Data Model class that is used to format the error message. An error message is formatted using a format string that is defined in the export component's StringTable resource, and is referred to by an identifier such as IDS_MB_FILE_READONLY. The format string can have placeholders for values to be inserted when the message is formatted. You can define your own error messages by adding new format strings to the StringTable resource. See the existing resources for examples, and refer to topics on inserting new entries into the string table in the Microsoft Developer Network (MSDN) for example:
https://msdn.microsoft.com/en-us/library/467c6ycx.aspx
See also
Creating an export component