C++ (Qt) if ( errorCode != ErrorType::errNone ) { return showError( iFileName, errorCode ); }}
C++ (Qt) if (error) return showError(error, iFileName);
C++ (Qt)int main() { std::string fileNameIn = "input.txt"; int firstNumber = 0; int secondNumber = 0; try { readData( fileNameIn, firstNumber, secondNumber ); } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } int result = sum(firstNumber, secondNumber); std::string fileNameOut = "output.txt"; try { writeResult( fileNameOut, result ); } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } return 0;}
C++ (Qt)int sum(int firstNumber, int secondNumber) { return 0;}
C++ (Qt) QTest::addColumn<int>("firstNumber"); QTest::addColumn<int>("secondNumber"); QTest::addColumn<int>("expected"); QTest::newRow("sum_01") << 1 << 2 << 3; QTest::newRow("sum_02") << -1 << -2 << -3; QTest::newRow("sum_03") << -3 << 5 << 2; QTest::newRow("sum_04") << 5 << -3 << 2; QTest::newRow("sum_05") << -5 << 3 << -2;
C++ (Qt)//#define TESTING#ifndef TESTING// ...int main() { // ...}#endif // TESTING int sum(int firstNumber, int secondNumber) { int result = firstNumber + secondNumber; return result;}
C++ (Qt)SOURCES += \ main.cpp
C++ (Qt)//#define TESTING#ifndef TESTING #include <iostream>#include <stdexcept>#include <string>#include <sstream>#include <fstream> class FileError : public std::runtime_error {public: FileError( const std::string &fileIn ) : std::runtime_error( "" ), m_file( fileIn ) { } virtual const char* what( ) const throw() { return m_msg.c_str( ); } std::string getFileName( ) const { return m_file; } virtual ~FileError() throw() { } protected: std::string m_file; std::string m_msg;}; class FileOpenError : public FileError {public: FileOpenError( const std::string &fileNameIn ) : FileError( fileNameIn ) { m_msg = "Unable to open " + fileNameIn; }}; class FileReadError : public FileError {public: FileReadError( const std::string &fileNameIn, int lineNumIn ) : FileError( fileNameIn ), m_lineNum( lineNumIn ) { std::ostringstream ostr; ostr << "Error reading " << fileNameIn << " at line " << lineNumIn; m_msg = ostr.str( ); } int getLineNum( ) const { return m_lineNum; } protected: int m_lineNum;}; class FileWriteError : public FileError {public: FileWriteError( const std::string &fileNameIn ) : FileError( fileNameIn ) { m_msg = "Unable to write " + fileNameIn; }}; void readData( const std::string &fileName, int &firstNumber, int &secondNumber )throw (FileOpenError, FileReadError); void writeResult( const std::string &fileName, int number )throw (FileOpenError, FileWriteError); int sum(int firstNumber, int secondNumber); int main() { std::string fileNameIn = "input.txt"; int firstNumber = 0; int secondNumber = 0; try { readData( fileNameIn, firstNumber, secondNumber ); } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } int result = sum(firstNumber, secondNumber); std::string fileNameOut = "output.txt"; try { writeResult( fileNameOut, result ); } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } return 0;} void readData( const std::string &fileName, int &firstNumber, int &secondNumber )throw ( FileOpenError, FileReadError ) { std::ifstream file; file.open( fileName.c_str( ) ); if ( file.fail( ) ) { throw FileOpenError( fileName ); } int lineNumIn = 0; if ( !( file >> firstNumber >> secondNumber ) ) { lineNumIn++; throw FileReadError( fileName, lineNumIn ); }} void writeResult( const std::string &fileName, int number )throw (FileOpenError, FileWriteError) { std::ofstream file; file.open( fileName.c_str( ) ); if ( file.fail( ) ) { throw FileOpenError( fileName ); } if ( !( file << number ) ) { throw FileWriteError( fileName ); } file << std::endl;}#endif // TESTING int sum(int firstNumber, int secondNumber) { int result = firstNumber + secondNumber; return result;}
C++ (Qt)#-------------------------------------------------## Project created by QtCreator 2014-04-03T19:03:48##------------------------------------------------- QT += testlib QT -= gui TARGET = tst_SumTestsCONFIG += consoleCONFIG -= app_bundle TEMPLATE = app SOURCES += tst_SumTests.cppSOURCES += ../acmp_0001_sum/main.cppDEFINES += SRCDIR=\\\"$$PWD/\\\"
C++ (Qt)#include <QString>#include <QtTest> int sum(int firstNumber, int secondNumber); class SumTests : public QObject{ Q_OBJECT public: SumTests(); private Q_SLOTS: void testCase1_data(); void testCase1();}; SumTests::SumTests(){} void SumTests::testCase1_data(){ QTest::addColumn<int>("firstNumber"); QTest::addColumn<int>("secondNumber"); QTest::addColumn<int>("expected"); QTest::newRow("sum_01") << 1 << 2 << 3; QTest::newRow("sum_02") << -1 << -2 << -3; QTest::newRow("sum_03") << -3 << 5 << 2; QTest::newRow("sum_04") << 5 << -3 << 2; QTest::newRow("sum_05") << -5 << 3 << -2;} void SumTests::testCase1(){ QFETCH(int, firstNumber); QFETCH(int, secondNumber); QFETCH(int, expected); int actual = sum(firstNumber, secondNumber); QCOMPARE(actual, expected);} QTEST_APPLESS_MAIN(SumTests) #include "tst_SumTests.moc"
C++ (Qt)class LogicError : public std::logic_error {public: LogicError( int argument ) : std::logic_error( "" ), m_argument( argument ) { } virtual const char *what( ) const throw () { return m_message.c_str( ); } virtual ~LogicError( ) throw () { } protected: int m_argument; std::string m_message;}; class InvalidArgument : public LogicError {public: InvalidArgument( int argument ) : LogicError( argument ) { std::stringstream stream; stream << argument; m_message = "Argument " + stream.str( ) + " mush be multiple of 5"; }}; class OutOfRange : public LogicError {public: OutOfRange( int argument, int beginOfRange, int endOfRange ) : LogicError( argument ) { std::stringstream stream; std::string str_argument, str_beginOfRange, str_endOfRange; stream << argument; str_argument = stream.str(); stream.str(""); stream << beginOfRange; str_beginOfRange = stream.str(); stream.str(""); stream << endOfRange; str_endOfRange = stream.str(); stream.str(""); m_message = "Argument " + str_argument + " don't hit on the range [" + str_beginOfRange + ", " + str_endOfRange + "]"; }};
C++ (Qt)double fiveAndFive( int number ) throw (InvalidArgument, OutOfRange);
C++ (Qt) int result = 0; try { result = fiveAndFive(number); } catch ( const LogicError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Uncaught exception." << std::endl; return 1; }
C++ (Qt)double fiveAndFive( int number ) throw (InvalidArgument, OutOfRange) { if ( (number % 5) != 0 ) { throw InvalidArgument( number ); } const int beginOfRange = 5; const int endOfRange = 400000; if ( (number < beginOfRange) || (endOfRange < number) ) { throw OutOfRange( number, beginOfRange, endOfRange ); } double result = (double) number * (double) number; return result;}
C++ (Qt)#include <stdexcept>#include <string>#include <sstream> //#define TESTING#ifndef TESTING #include <iostream>#include <fstream> class FileError : public std::runtime_error {public: FileError( const std::string &fileIn ) : std::runtime_error( "" ), m_file( fileIn ) { } virtual const char* what( ) const throw() { return m_msg.c_str( ); } std::string getFileName( ) const { return m_file; } virtual ~FileError() throw() { } protected: std::string m_file; std::string m_msg;}; class FileOpenError : public FileError {public: FileOpenError( const std::string &fileNameIn ) : FileError( fileNameIn ) { m_msg = "Unable to open " + fileNameIn; }}; class FileReadError : public FileError {public: FileReadError( const std::string &fileNameIn, int lineNumIn ) : FileError( fileNameIn ), m_lineNum( lineNumIn ) { std::ostringstream ostr; ostr << "Error reading " << fileNameIn << " at line " << lineNumIn; m_msg = ostr.str( ); } int getLineNum( ) const { return m_lineNum; } protected: int m_lineNum;}; class FileWriteError : public FileError {public: FileWriteError( const std::string &fileNameIn ) : FileError( fileNameIn ) { m_msg = "Unable to write " + fileNameIn; }};#endif // TESTING class LogicError : public std::logic_error {public: LogicError( int argument ) : std::logic_error( "" ), m_argument( argument ) { } virtual const char *what( ) const throw () { return m_message.c_str( ); } virtual ~LogicError( ) throw () { } protected: int m_argument; std::string m_message;}; class InvalidArgument : public LogicError {public: InvalidArgument( int argument ) : LogicError( argument ) { std::stringstream stream; stream << argument; m_message = "Argument " + stream.str( ) + " mush be multiple of 5"; }}; class OutOfRange : public LogicError {public: OutOfRange( int argument, int beginOfRange, int endOfRange ) : LogicError( argument ) { std::stringstream stream; stream << argument << beginOfRange << endOfRange; std::string str_argument, str_beginOfRange, str_endOfRange; stream >> str_argument >> str_beginOfRange >> str_endOfRange; m_message = "Argument " + str_argument + " don't hit on the range [" + str_beginOfRange + ", " + str_endOfRange + "]"; }}; #ifndef TESTINGvoid readData( const std::string &fileName, int &number )throw (FileOpenError, FileReadError); void writeResult( const std::string &fileName, int result )throw (FileOpenError, FileWriteError); double fiveAndFive( int number ) throw (InvalidArgument, OutOfRange); int main() { std::string fileNameIn = "input.txt"; int number = 0; try { readData( fileNameIn, number ); } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Uncaught exception." << std::endl; return 1; } int result = 0; try { result = fiveAndFive(number); } catch ( const LogicError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Uncaught exception." << std::endl; return 1; } std::string fileNameOut = "output.txt"; try { writeResult( fileNameOut, result ); } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } return 0;} void readData( const std::string &fileName, int &number )throw ( FileOpenError, FileReadError ) { std::ifstream file; file.open( fileName.c_str( ) ); if ( file.fail( ) ) { throw FileOpenError( fileName ); } int lineNumIn = 0; if ( !( file >> number ) ) { lineNumIn++; throw FileReadError( fileName, lineNumIn ); }} void writeResult( const std::string &fileName, int result )throw (FileOpenError, FileWriteError) { std::ofstream file; file.open( fileName.c_str( ) ); if ( file.fail( ) ) { throw FileOpenError( fileName ); } if ( !( file << result ) ) { throw FileWriteError( fileName ); } file << std::endl;}#endif // TESTING double fiveAndFive( int number ) throw (InvalidArgument, OutOfRange) { if ( (number % 5) != 0 ) { throw InvalidArgument( number ); } const int beginOfRange = 5; const int endOfRange = 400000; if ( (number < beginOfRange) || (endOfRange < number) ) { throw OutOfRange( number, beginOfRange, endOfRange ); } double result = (double) number * (double) number; return result;}
C++ (Qt)class OutOfRange : public LogicError {public: OutOfRange( int argument, int beginOfRange, int endOfRange ) : LogicError( argument ) { std::stringstream stream; stream << argument << beginOfRange << endOfRange; std::string str_argument, str_beginOfRange, str_endOfRange; stream >> str_argument >> str_beginOfRange >> str_endOfRange; m_message = "Argument " + str_argument + " don't hit on the range [" + str_beginOfRange + ", " + str_endOfRange + "]"; }};
C++ (Qt)class OutOfRange : public LogicError {public: OutOfRange( int argument, int beginOfRange, int endOfRange ) : LogicError( argument ) { std::stringstream stream; std::string str_argument, str_beginOfRange, str_endOfRange; stream << argument; str_argument = stream.str(); stream.str(""); stream << beginOfRange; str_beginOfRange = stream.str(); stream.str(""); stream << endOfRange; str_endOfRange = stream.str(); stream.str(""); m_message = "Argument " + str_argument + " don't hit on the range [" + str_beginOfRange + ", " + str_endOfRange + "]"; }};
C++ (Qt)std::string intToString( int number ) { std::stringstream stream; stream << number; return stream.str( );} class OutOfRange : public LogicError {public: OutOfRange( int argument, int beginOfRange, int endOfRange ) : LogicError( argument ) { std::string str_argument, str_beginOfRange, str_endOfRange; str_argument = intToString( argument ); str_beginOfRange = intToString( beginOfRange ); str_endOfRange = intToString( endOfRange ); m_message = "Argument " + str_argument + " don't hit on the range [" + str_beginOfRange + ", " + str_endOfRange + "]"; }};
C++ (Qt)QT += core QT -= gui TARGET = FiveAndFiveCONFIG += consoleCONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp \ FiveAndFive.cpp HEADERS += \ FiveAndFive.h \ FileError.h \ FileOpenError.h \ FileReadError.h \ FileWriteError.h \ LogicError.h \ InvalidArgument.h \ OutOfRange.h
C++ (Qt)#ifndef FIVEANDFIVE_H#define FIVEANDFIVE_H #include "InvalidArgument.h"#include "OutOfRange.h" class FiveAndFive {public: double fiveAndFive( int number ) throw (InvalidArgument, OutOfRange);}; #endif // FIVEANDFIVE_H
C++ (Qt)#include "FiveAndFive.h" double FiveAndFive::fiveAndFive( int number ) throw (InvalidArgument, OutOfRange) { if ( (number % 5) != 0 ) { throw InvalidArgument( number ); } const int beginOfRange = 5; const int endOfRange = 400000; if ( (number < beginOfRange) || (endOfRange < number) ) { throw OutOfRange( number, beginOfRange, endOfRange ); } double result = (double) number * (double) number; return result;}
C++ (Qt)#include <QCoreApplication>#include <iostream>#include <fstream>#include "FiveAndFive.h"#include "FileError.h"#include "FileOpenError.h"#include "FileReadError.h"#include "FileWriteError.h"#include "LogicError.h" void readData( const std::string &fileName, int &number )throw (FileOpenError, FileReadError); void writeResult( const std::string &fileName, int result )throw (FileOpenError, FileWriteError); int main( int argc, char *argv[] ) { QCoreApplication a( argc, argv ); std::string fileNameIn = "input.txt"; int number = 0; try { readData( fileNameIn, number ); } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Uncaught exception." << std::endl; return 1; } int result = 0; FiveAndFive faf; try { result = faf.fiveAndFive( number ); } catch ( const LogicError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Uncaught exception." << std::endl; return 1; } std::string fileNameOut = "output.txt"; try { writeResult( fileNameOut, result ); } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } std::cout << "See file " << fileNameOut << std::endl; return a.exec( );} void readData( const std::string &fileName, int &number )throw ( FileOpenError, FileReadError) { std::ifstream file; file.open( fileName.c_str( ) ); if ( file.fail( ) ) { throw FileOpenError( fileName ); } int lineNumIn = 0; if ( !(file >> number) ) { lineNumIn++; throw FileReadError( fileName, lineNumIn ); }} void writeResult( const std::string &fileName, int result )throw (FileOpenError, FileWriteError) { std::ofstream file; file.open( fileName.c_str( ) ); if ( file.fail( ) ) { throw FileOpenError( fileName ); } if ( !(file << result) ) { throw FileWriteError( fileName ); } file << std::endl;}
C++ (Qt)#ifndef LOGICERROR_H#define LOGICERROR_H #include <string>#include <stdexcept> class LogicError : public std::logic_error {public: LogicError( int argument ) : std::logic_error( "" ), m_argument( argument ) { } virtual const char *what( ) const throw () { return m_message.c_str( ); } virtual ~LogicError( ) throw () { } protected: int m_argument; std::string m_message;}; #endif // LOGICERROR_H
C++ (Qt)#ifndef INVALIDARGUMENT_H#define INVALIDARGUMENT_H #include <string>#include <sstream>#include "LogicError.h" class InvalidArgument : public LogicError {public: InvalidArgument( int argument ) : LogicError( argument ) { std::stringstream stream; stream << argument; m_message = "Argument " + stream.str( ) + " mush be multiple of 5"; }}; #endif // INVALIDARGUMENT_H
C++ (Qt)#ifndef OUTOFRANGE_H#define OUTOFRANGE_H #include <string>#include <sstream>#include "LogicError.h" class OutOfRange : public LogicError {public: OutOfRange( int argument, int beginOfRange, int endOfRange ) : LogicError( argument ) { std::string str_argument, str_beginOfRange, str_endOfRange; str_argument = intToString( argument ); str_beginOfRange = intToString( beginOfRange ); str_endOfRange = intToString( endOfRange ); m_message = "Argument " + str_argument + " don't hit on the range [" + str_beginOfRange + ", " + str_endOfRange + "]"; } private: std::string intToString( int number ) { std::stringstream stream; stream << number; return stream.str( ); }}; #endif // OUTOFRANGE_H
C++ (Qt)#ifndef FILEERROR_H#define FILEERROR_H #include <string>#include <stdexcept> class FileError : public std::runtime_error {public: FileError( const std::string &fileIn ) : std::runtime_error( "" ), m_file( fileIn ) { } virtual const char* what( ) const throw() { return m_msg.c_str( ); } virtual ~FileError() throw() { } protected: std::string m_file; std::string m_msg;}; #endif // FILEERROR_H
C++ (Qt)#ifndef FILEOPENERROR_H#define FILEOPENERROR_H #include <string>#include "FileError.h" class FileOpenError : public FileError {public: FileOpenError( const std::string &fileNameIn ) : FileError( fileNameIn ) { m_msg = "Unable to open " + fileNameIn; }}; #endif // FILEOPENERROR_H
C++ (Qt)#ifndef FILEREADERROR_H#define FILEREADERROR_H #include <string>#include <sstream>#include "FileError.h" class FileReadError : public FileError {public: FileReadError( const std::string &fileNameIn, int lineNumIn ) : FileError( fileNameIn ), m_lineNum( lineNumIn ) { std::ostringstream ostr; ostr << "Error reading " << fileNameIn << " at line " << lineNumIn; m_msg = ostr.str( ); } protected: int m_lineNum;}; #endif // FILEREADERROR_H
C++ (Qt)#ifndef FILEWRITEERROR_H#define FILEWRITEERROR_H #include <string>#include "FileError.h" class FileWriteError : public FileError {public: FileWriteError( const std::string &fileNameIn ) : FileError( fileNameIn ) { m_msg = "Unable to write " + fileNameIn; }}; #endif // FILEWRITEERROR_H
C++ (Qt)INCLUDEPATH += "../FiveAndFive"SOURCES += ../FiveAndFive/FiveAndFive.cpp
C++ (Qt)QT += testlib QT -= gui TARGET = tst_FiveAndFiveTestsCONFIG += consoleCONFIG -= app_bundle TEMPLATE = app SOURCES += tst_FiveAndFiveTests.cppINCLUDEPATH += "../FiveAndFive"SOURCES += ../FiveAndFive/FiveAndFive.cppDEFINES += SRCDIR=\\\"$$PWD/\\\"
C++ (Qt)#include <QString>#include <QtTest> #include "FiveAndFive.h" class FiveAndFiveTests : public QObject { Q_OBJECT public: FiveAndFiveTests( ); static inline bool qFuzzyCompare( double p1, double p2, double delta ) { return ( qAbs( p1 - p2 ) <= delta * qMin( qAbs( p1 ), qAbs( p2 ) )); } privateQ_SLOTS: void testCase1_data( ); void testCase1( );}; FiveAndFiveTests::FiveAndFiveTests( ) {} void FiveAndFiveTests::testCase1_data( ) { QTest::addColumn<int>("number"); QTest::addColumn<double>("expected"); QTest::addColumn<bool>("isExpectedException"); bool exception = true; bool no_exception = false; QTest::newRow( "fiveAndFive_02" ) << 0 << 0.0 << exception; QTest::newRow( "fiveAndFive_01" ) << 1 << 0.0 << exception; QTest::newRow( "fiveAndFive_03" ) << 4 << 0.0 << exception; QTest::newRow( "fiveAndFive_04" ) << 5 << 25.0 << no_exception; QTest::newRow( "fiveAndFive_05" ) << 6 << 0.0 << exception; QTest::newRow( "fiveAndFive_06" ) << 399995 << 159996000025.0 << no_exception; QTest::newRow( "fiveAndFive_07" ) << 400000 << 160000000000.0 << no_exception; QTest::newRow( "fiveAndFive_08" ) << 400001 << 0.0 << exception; QTest::newRow( "fiveAndFive_09" ) << 400005 << 0.0 << exception;} void FiveAndFiveTests::testCase1( ) { QFETCH( int, number ); QFETCH( double, expected ); QFETCH( bool, isExpectedException ); double delta = 0.0001; FiveAndFive faf; try { double actual = faf.fiveAndFive( number ); bool result = qFuzzyCompare( actual, expected, delta ); if ( isExpectedException ) { QVERIFY2( false, "There is no exception." ); } else { QString msg = QString( "\nActual: %1" "\nExpected: %2" "\nDelta: %3" ).arg( actual ).arg( expected ).arg( delta ); QVERIFY2( result, msg.toStdString( ).c_str( ) ); } } catch ( const LogicError& e ) { if ( !isExpectedException ) { QVERIFY2( false, "Exception was occur." ); } else { QVERIFY2( true, "" ); } } catch ( ... ) { QVERIFY2( false, "Uncaught exception." ); }} QTEST_APPLESS_MAIN( FiveAndFiveTests ) #include "tst_FiveAndFiveTests.moc"
C++ (Qt)#include <QCoreApplication>#include <string>#include <iostream>#include "boost/lexical_cast.hpp" int main( int argc, char *argv[] ) { QCoreApplication a( argc, argv ); int i = 5; std::string s = boost::lexical_cast<std::string>(i); std::cout << s << std::endl; double d = 5.5; s = boost::lexical_cast<std::string>(d); std::cout << s << std::endl; return a.exec( );}
C++ (Qt)#include <vector>#include <string>#include <iostream>#include <fstream>#include <sstream>using namespace std; int sumOfMaxAndMin(const vector<int>& arr) { int sum = 0; return sum;} int main(int argc, char** argv) { string inFileName = "input.txt"; ifstream in; in.open(inFileName.c_str()); if (!in.is_open()) { cerr << "Error: could not open the file " << inFileName.c_str() << endl; return 1; } string outFileName = "output.txt"; ofstream out; out.open(outFileName.c_str()); if (!out.is_open()) { cerr << "Error: could not open the file " << outFileName.c_str() << endl; in.close(); return 1; } vector<int> arr; int value; string input; stringstream stream; while (in >> input) { stream << input; if (stream >> value) { cout << value << endl; } else { cerr << "Error: incorrect data in the file " << inFileName.c_str() << endl; in.close(); out.close(); return 1; } } int sum = sumOfMaxAndMin(arr); out << sum << endl; in.close(); out.close(); return 0;}
C++ (Qt)int main(int argc, char** argv) { std::vector <int> vec; // получаем имя файла из командной строки, если там пусто, то input.txt (по умолчанию) std::string iFileName = GetInName(argc, argv); // читаем данные из файла int err = ReadData(iFileName, vec); if (err) return ShowError(err, &iFileName); // выполняем содержательную часть int result; err = sumOfMaxAndMin(arr, &result); if (err) return ShowError(err, &iFileName); // записываем выходной файл std::string oFileName = GetOutName(argc, argv); err = WriteResult(oFileName, result); if (err) return ShowError(err, &oFileName); return 0;}
...} catch ( const FileError &e) { std::cerr << e.what( ) << std::endl; return 1;...
C++ (Qt)#include <iostream>#include <string>#include <vector>#include <QString>#include "freeFunctions.h"#include "LogicError.h"#include "FileError.h" int main( ){ // Read data from the input file QString fileNameIn = "input.txt"; QString content; try { readData( fileNameIn, content ); } catch ( const LogicError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( const FileError &e) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Error: unknown exception" << std::endl; return 1; } // Parse the content to the integer array std::vector<int> arr; try { parseToIntArray( content, arr ); } catch ( const LogicError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Error: unknown exception" << std::endl; return 1; } // Write data to the output file QString fileNameOut = "output.txt"; try { writeData( fileNameOut, arr ); } catch ( const LogicError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Error: unknown exception" << std::endl; return 1; } return 0;}