C++ (Qt)void readData( const QString &fileName, QVector<int> &arr ) throw (FileOpenError, FileReadError);
C++ (Qt) try { readData( iFileName, arr ); } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; }
C++ (Qt)#include <iostream> int main( ) { int* ptr; int numInts = 10; try { ptr = new int[numInts]; } catch ( const std::bad_alloc& e ) { std::cerr << __FILE__ << "(" << __LINE__ << "): Unable to allocate memory!" << std::endl; // Handle memory allocation failure return 1; } // Proceed with function that assumes memory has been allocated return 0;}
C++ (Qt)#include <iostream> int main( ) { int* ptr; int numInts = 10; ptr = new(std::nothrow) int[numInts]; if ( ptr == nullptr ) { std::cerr << __FILE__ << "(" << __LINE__ << "): Unable to allocate memory!" << std::endl; // Handle memory allocation failure return 1; } // Proceed with function that assumes memory has been allocated return 0;}