comfortSDK
Most functions of comfortC return a status code. Additionally comfortC offers error messages with extended information. The error message can be retrieved via the peak_Library_GetLastError function. It is recommended to encapsulate this call in a separate function.
| #include <ids_peak_comfort_c.h>
 peak_bool checkForSuccess(peak_status checkStatus);
 
 int main()
 {
 // Initialize IDS peak library
 peak_status status = peak_Library_Init();
 if (!checkForSuccess(status))
 {
 // Return, if the initialization of the library failed
 return status;
 }
 
 // Create camera handle
 peak_camera_handle hCam = PEAK_INVALID_HANDLE;
 
 // Update camera list
 status = peak_CameraList_Update(NULL);
 if (!checkForSuccess(status))
 {
 // Return, if the update of the camera list failed
 
 // Exit library first
 status = peak_Library_Exit();
 checkForSuccess(status);
 
 return status;
 }
 
 // Open first available camera
 status = peak_Camera_OpenFirstAvailable(&hCam);
 if (!checkForSuccess(status))
 {
 // Handling if the camera could not be opened e.g. print a
 // message to connect a camera and repeat camera list update
 // ...
 
 }
 
 // ...
 
 }
 
 peak_bool checkForSuccess(peak_status checkStatus)
 {
 if (PEAK_ERROR(checkStatus))
 {
 peak_status lastErrorCode = PEAK_STATUS_SUCCESS;
 size_t lastErrorMessageSize = 0;
 
 // Get size of error message
 peak_status status = peak_Library_GetLastError(&lastErrorCode, NULL, &lastErrorMessageSize);
 if (PEAK_ERROR(status))
 {
 // Something went wrong getting the last error!
 printf("Last-Error: Getting last error code failed! Status: %#06x\n", status);
 return PEAK_FALSE;
 }
 
 if (checkStatus != lastErrorCode)
 {
 // Another error occured in the meantime. Proceed with the last error.
 printf("Last-Error: Another error occured in the meantime!\n");
 }
 
 // Allocate and zero-initialize the char array for the error message
 char* lastErrorMessage = (char*)calloc((lastErrorMessageSize) / sizeof(char), sizeof(char));
 if (lastErrorMessage == NULL)
 {
 // Cannot allocate lastErrorMessage. Most likely not enough Memory.
 printf("Last-Error: Failed to allocate memory for the error message!\n");
 free(lastErrorMessage);
 return PEAK_FALSE;
 }
 
 // Get the error message
 status = peak_Library_GetLastError(&lastErrorCode, lastErrorMessage, &lastErrorMessageSize);
 if (PEAK_ERROR(status))
 {
 // Unable to get error message. This shouldn't ever happen.
 printf("Last-Error: Getting last error message failed! Status: %#06x; Last error code: %#06x\n", status,
 lastErrorCode);
 free(lastErrorMessage);
 return PEAK_FALSE;
 }
 
 printf("Last-Error: %s | Code: %#06x\n", lastErrorMessage, lastErrorCode);
 free(lastErrorMessage);
 
 return PEAK_FALSE;
 }
 return PEAK_TRUE;
 }
 | 
genericSDK
If an error occurs, IDS peak throws an exception. Use try-catch blocks for exception handling. A try-catch block marks some of the statements to be executed and defines an action when an exception occurs.
| try{
 // do something here
 // ...
 }
 catch (const std::exception& e)
 {
 std::cout << "EXCEPTION: " << e.what() << std::endl;
 }
 | 
| try{
 // do something here
 // ...
 catch (System.ApplicationException e)
 {
 Console.WriteLine("Exception: " + e.Message);
 }
 | 
| try:# do something here
 # ...
 except Exception as e:
 print("Exception: " + str(e) + "")
 |