MOAB: Mesh Oriented datABase  (version 5.4.1)
ErrorHandlingSimulation.cpp File Reference
#include "moab/MOABConfig.h"
#include "moab/ErrorHandler.hpp"
#include <iostream>
#include <cstdlib>
+ Include dependency graph for ErrorHandlingSimulation.cpp:

Go to the source code of this file.

Functions

ErrorCode FunctionC (int test_case_num, int rank)
ErrorCode FunctionB (int test_case_num, int rank)
ErrorCode FunctionA (int test_case_num, int rank)
int main (int argc, char **argv)

Function Documentation

ErrorCode FunctionA ( int  test_case_num,
int  rank 
)
Examples:
ErrorHandlingSimulation.cpp.

Definition at line 68 of file ErrorHandlingSimulation.cpp.

References ErrorCode, FunctionB(), MB_CHK_ERR, and MB_SUCCESS.

Referenced by main().

{
    ErrorCode err_code = FunctionB( test_case_num, rank );MB_CHK_ERR( err_code );

    return MB_SUCCESS;
}
ErrorCode FunctionB ( int  test_case_num,
int  rank 
)
Examples:
ErrorHandlingSimulation.cpp.

Definition at line 61 of file ErrorHandlingSimulation.cpp.

References ErrorCode, FunctionC(), MB_CHK_ERR, and MB_SUCCESS.

Referenced by FunctionA().

{
    ErrorCode err_code = FunctionC( test_case_num, rank );MB_CHK_ERR( err_code );

    return MB_SUCCESS;
}
ErrorCode FunctionC ( int  test_case_num,
int  rank 
)
Examples:
ErrorHandlingSimulation.cpp.

Definition at line 24 of file ErrorHandlingSimulation.cpp.

References MB_INDEX_OUT_OF_RANGE, MB_NOT_IMPLEMENTED, MB_SET_ERR, MB_SET_GLB_ERR, MB_SUCCESS, and MB_TYPE_OUT_OF_RANGE.

Referenced by FunctionB().

{
    switch( test_case_num )
    {
        case 1:
            // Simulate a global fatal error MB_NOT_IMPLEMENTED on all processors
            // Note, it is printed by root processor 0 only
            MB_SET_GLB_ERR( MB_NOT_IMPLEMENTED, "A contrived global error MB_NOT_IMPLEMENTED" );
            break;
        case 2:
            // Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on all processors
            // Note, it is printed by all processors
            MB_SET_ERR( MB_INDEX_OUT_OF_RANGE, "A contrived error MB_INDEX_OUT_OF_RANGE on processor " << rank );
            break;
        case 3:
            // Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on all processors except
            // root Note, it is printed by all non-root processors
            if( 0 != rank )
                MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "A contrived error MB_TYPE_OUT_OF_RANGE on processor " << rank );
            break;
        case 4:
            // Simulate a per-processor relevant error MB_INDEX_OUT_OF_RANGE on processor 1
            // Note, it is printed by processor 1 only
            if( 1 == rank )
                MB_SET_ERR( MB_INDEX_OUT_OF_RANGE, "A contrived error MB_INDEX_OUT_OF_RANGE on processor 1" );

            // Simulate a per-processor relevant error MB_TYPE_OUT_OF_RANGE on processor 3
            // Note, it is printed by processor 3 only
            if( 3 == rank ) MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "A contrived error MB_TYPE_OUT_OF_RANGE on processor 3" );
            break;
        default:
            break;
    }

    return MB_SUCCESS;
}
int main ( int  argc,
char **  argv 
)

Definition at line 75 of file ErrorHandlingSimulation.cpp.

References ErrorCode, FunctionA(), MB_CHK_ERR, moab::MBErrorHandler_Finalize(), moab::MBErrorHandler_Init(), MPI_COMM_WORLD, and rank.

{
    if( argc < 2 )
    {
        cout << "Usage: " << argv[0] << " <test_case_num(1 to 4)>" << endl;
        return 0;
    }

#ifdef MOAB_HAVE_MPI
    MPI_Init( &argc, &argv );
#endif

    // Initialize error handler, required for this example (not using a moab instance)
    MBErrorHandler_Init();

    int test_case_num = atoi( argv[1] );
    int rank          = 0;
#ifdef MOAB_HAVE_MPI
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
#endif

    ErrorCode rval = FunctionA( test_case_num, rank );MB_CHK_ERR( rval );

    // Finalize error handler, required for this example (not using a moab instance)
    MBErrorHandler_Finalize();

#ifdef MOAB_HAVE_MPI
    MPI_Finalize();
#endif

    return 0;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines