Project Files/Testing Source/main.cpp
void errorReporting() {
    //Create the Task Manager
    if (AsynchTasks::TaskManager::create(1)) {
        //Store a user string
        char usrError[256];

        //Get a custom error message from the user
        do {
            //Clear the screen
            system("CLS");

            //Get the message from the user
            getInput(usrError, "Enter an error message to be reported on error thrown (Max 256 characters): ");
        } while (!strlen(usrError));

        //Add some space on screen
        printf("\n\n\n");

        //Create the basic input manager
        BasicInput input = BasicInput(VK_ESCAPE, VK_SPACE);

        //Store a flag for describing the position the error should be called
        bool errorFlag = false;

        //Setup the basic task to throw the error after a period of time
        AsynchTasks::Task<void> errorTask = AsynchTasks::TaskManager::createTask<void>();

        //Setup the error task with its values
        errorTask->callbackOnUpdate = false;
        errorTask->process = [&]() {
            //Sleep the thread for a period of time
            std::this_thread::sleep_for(std::chrono::milliseconds(randomRange(2000U, 5000U)));

            //Test to see if the error should be thrown here
            if (!errorFlag) {
                //Toggle the flag
                errorFlag = true;

                //Throw the users error
                throw std::runtime_error(std::string("Task Process function threw the error: ") + usrError);
            }
        };
        errorTask->callback = [&]() {
            //Toggle the flag
            errorFlag = false;

            //Throw the users error
            throw std::runtime_error(std::string("Task Callback function threw the error: ") + usrError);
        };

        //Store the previous status of the Task
        AsynchTasks::ETaskStatus prevStatus = AsynchTasks::ETaskStatus::Error;

        //Output the starting message
        printf("Press 'SPACE' to start the Task. Task progress and error output will be displayed\n\n");

        //Loop till escape is pressed
        while (!input.keyPressed(VK_ESCAPE)) {
            //Update the Input
            input.update();

            //Update the Task Manager
            AsynchTasks::TaskManager::update();

            //Check the Task status
            if (errorTask->status != prevStatus) {
                //Set the new status value
                prevStatus = errorTask->status;

                //Output the new status of the Task
                printf("Task Status: %s (%i)\n", statusToName(prevStatus), prevStatus);

                //If the task has failed
                if (prevStatus == AsynchTasks::ETaskStatus::Error) {
                    //Output the error message
                    printf("%s\n\n\n", errorTask->error.value().c_str());

                    //Force the task to reset itself
                    errorTask->callbackOnUpdate = (bool)errorTask->callbackOnUpdate;
                }
            }

            //Check to see if the user wants to add the Task to the manager
            if (input.keyPressed(VK_SPACE) && (errorTask->status == AsynchTasks::ETaskStatus::Setup || errorTask->status == AsynchTasks::ETaskStatus::Error))
                AsynchTasks::TaskManager::addTask(errorTask);
        }
    }

    //Display error message
    else printf("Failed to create the Asynchronous Task Manager\n");

    //Destroy the the Task Manager
    AsynchTasks::TaskManager::destroy();
}
/*
    errorReporting - Test task error reporting to the user upon exception thrown
    Author: Mitchell Croft
    Created: 12/01/2017
    Modified: 12/01/2017
*/
Test task error reporting to the user upon exception thrown
Author: Mitchell Croft
Created: 12/01/2017
Modified: 12/01/2017
Test task error reporting to the user upon exception thrown Author : Mitchell Croft Created : 12 / 01 / 2017 Modified : 12 / 01 / 2017
void errorReporting() {
    if (AsynchTasks::TaskManager::create(1)) {
        char usrError[256];
        do {
            system("CLS");
            getInput(usrError, "Enter an error message to be reported on error thrown (Max 256 characters): ");
        } while (!strlen(usrError));
        printf("\n\n\n");
        BasicInput input = BasicInput(VK_ESCAPE, VK_SPACE);
        bool errorFlag = false;
        AsynchTasks::Task<void> errorTask = AsynchTasks::TaskManager::createTask<void>();
        errorTask->callbackOnUpdate = false;
        errorTask->process = [&]() {
            std::this_thread::sleep_for(std::chrono::milliseconds(randomRange(2000U, 5000U)));
            if (!errorFlag) {
                errorFlag = true;
                throw std::runtime_error(std::string("Task Process function threw the error: ") + usrError);
            }
        };
        errorTask->callback = [&]() {
            errorFlag = false;
            throw std::runtime_error(std::string("Task Callback function threw the error: ") + usrError);
        };
        AsynchTasks::ETaskStatus prevStatus = AsynchTasks::ETaskStatus::Error;
        printf("Press 'SPACE' to start the Task. Task progress and error output will be displayed\n\n");
        while (!input.keyPressed(VK_ESCAPE)) {
            input.update();
            AsynchTasks::TaskManager::update();
            if (errorTask->status != prevStatus) {
                prevStatus = errorTask->status;
                printf("Task Status: %s (%i)\n", statusToName(prevStatus), prevStatus);
                if (prevStatus == AsynchTasks::ETaskStatus::Error) {
                    printf("%s\n\n\n", errorTask->error.value().c_str());
                    errorTask->callbackOnUpdate = (bool)errorTask->callbackOnUpdate;
                }
            }
            if (input.keyPressed(VK_SPACE) && (errorTask->status == AsynchTasks::ETaskStatus::Setup || errorTask->status == AsynchTasks::ETaskStatus::Error))
                AsynchTasks::TaskManager::addTask(errorTask);
        }
    }
    else printf("Failed to create the Asynchronous Task Manager\n");
    AsynchTasks::TaskManager::destroy();
}
void errorReporting ( ) { if ( AsynchTasks :: TaskManager :: create ( 1 ) ) { char usrError [ 256 ] ; do { system ( " " ) ; getInput ( usrError , " " ) ; } while ( ! strlen ( usrError ) ) ; printf ( " \n \n \n " ) ; BasicInput input = BasicInput ( VK_ESCAPE , VK_SPACE ) ; bool errorFlag = false ; AsynchTasks :: Task < void > errorTask = AsynchTasks :: TaskManager :: createTask < void > ( ) ; errorTask -> callbackOnUpdate = false ; errorTask -> process = [ & ] ( ) { std :: this_thread :: sleep_for ( std :: chrono :: milliseconds ( randomRange ( 2000U , 5000U ) ) ) ; if ( ! errorFlag ) { errorFlag = true ; throw std :: runtime_error ( std :: string ( " " ) + usrError ) ; } } ; errorTask -> callback = [ & ] ( ) { errorFlag = false ; throw std :: runtime_error ( std :: string ( " " ) + usrError ) ; } ; AsynchTasks :: ETaskStatus prevStatus = AsynchTasks :: ETaskStatus :: Error ; printf ( " \n \n " ) ; while ( ! input . keyPressed ( VK_ESCAPE ) ) { input . update ( ) ; AsynchTasks :: TaskManager :: update ( ) ; if ( errorTask -> status != prevStatus ) { prevStatus = errorTask -> status ; printf ( " \n " , statusToName ( prevStatus ) , prevStatus ) ; if ( prevStatus == AsynchTasks :: ETaskStatus :: Error ) { printf ( " \n \n \n " , errorTask -> error . value ( ) . c_str ( ) ) ; errorTask -> callbackOnUpdate = ( bool ) errorTask -> callbackOnUpdate ; } } if ( input . keyPressed ( VK_SPACE ) && ( errorTask -> status == AsynchTasks :: ETaskStatus :: Setup || errorTask -> status == AsynchTasks :: ETaskStatus :: Error ) ) AsynchTasks :: TaskManager :: addTask ( errorTask ) ; } } else printf ( " \n " ) ; AsynchTasks :: TaskManager :: destroy ( ) ; }
errorReporting - Test task error reporting to the user upon exception thrown
Author: Mitchell Croft
Created: 12/01/2017
Modified: 12/01/2017
errorReporting - Test task error reporting to the user upon exception thrown Author : Mitchell Croft Created : 12 / 01 / 2017 Modified : 12 / 01 / 2017
//Create the Task Manager //Store a user string //Get a custom error message from the user //Clear the screen //Get the message from the user //Add some space on screen //Create the basic input manager //Store a flag for describing the position the error should be called //Setup the basic task to throw the error after a period of time //Setup the error task with its values //Sleep the thread for a period of time //Test to see if the error should be thrown here //Toggle the flag //Throw the users error //Toggle the flag //Throw the users error //Store the previous status of the Task //Output the starting message //Loop till escape is pressed //Update the Input //Update the Task Manager //Check the Task status //Set the new status value //Output the new status of the Task //If the task has failed //Output the error message //Force the task to reset itself //Check to see if the user wants to add the Task to the manager //Display error message //Destroy the the Task Manager