ExceptionHandling.cpp shows the catching of an exception in Spinnaker. Following this, check out the Acquisition or NodeMapInfo examples if you haven't already. Acquisition demonstrates image acquisition while NodeMapInfo explores retrieving information from various node types.
This example shows three typical paths of exception handling in Spinnaker: catching the exception as a Spinnaker exception, as a standard exception, or as a standard exception which is then cast to a Spinnaker exception.
Once comfortable with Acquisition, ExceptionHandling, and NodeMapInfo, we suggest checking out AcquisitionMultipleCamera, NodeMapCallback, or SaveToAvi. AcquisitionMultipleCamera demonstrates simultaneously acquiring images from a number of cameras, NodeMapCallback serves as a good introduction to programming with callbacks and events, and SaveToAvi exhibits video creation.
#include <iostream>
#include <sstream>
using namespace Spinnaker;
using namespace Spinnaker::GenApi;
using namespace std;
{
};
{
const LibraryVersion spinnakerLibraryVersion = system->GetLibraryVersion();
cout <<
"Spinnaker library version: " << spinnakerLibraryVersion.
major <<
"." << spinnakerLibraryVersion.
minor
<<
"." << spinnakerLibraryVersion.
type <<
"." << spinnakerLibraryVersion.
build << endl
<< endl;
cout << "System retrieved..." << endl;
cout << "Camera list retrieved..." << endl;
{
cout << endl << "Not enough cameras!" << endl << endl;
return;
}
system->ReleaseInstance();
cout << "System released; this part of the code should not be reached..." << endl << endl;
}
{
const int k_maxNum = 10;
vector<int> numbers;
for (int i = 0; i < k_maxNum; i++)
{
numbers.push_back(i);
}
cout << "Vector initialized..." << endl << endl;
cout << "The highest number in the vector is " << numbers.at(k_maxNum) << ".";
}
{
cout << "Application build date: " << __DATE__ << " " << __TIME__ << endl << endl;
{
try
{
}
{
cout << endl << "Spinnaker exception caught." << endl << endl;
cout <<
"Error: " << ex.
what() << endl;
}
break;
try
{
}
catch (std::exception& ex)
{
cout << endl << "Standard exception caught." << endl << endl;
cout << "Error: " << ex.what() << endl;
}
break;
try
{
}
catch (std::exception& ex)
{
cout << endl << "Standard exception caught; will be cast as Spinnaker exception." << endl << endl;
try
{
}
catch (std::exception& stdEx)
{
cout << "Cannot cast; not a Spinnaker exception: " << stdEx.what() << endl;
cout << "Standard error: " << ex.what() << endl;
}
}
}
cout << endl << "Done! Press Enter to exit..." << endl;
getchar();
return 0;
}