示例#1
0
/*-------------------------------------------------------------------------
 * Function:	error_stack
 *
 * Purpose:	Manipulates current error stack.
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Raymond Lu
 *		July 14, 2003
 *
 *-------------------------------------------------------------------------
 */
static herr_t
error_stack(void)
{
    int err_num;
    const char          *FUNC_error_stack = "error_stack";

    if((err_num = H5Eget_num(H5E_DEFAULT)) < 0)
        TEST_ERROR;
    if(err_num)
        TEST_ERROR;

    if((ERR_STACK = H5Eget_current_stack()) < 0)
        TEST_ERROR;

    /* Make it push error, force this function to fail */
    if((err_num = H5Eget_num(ERR_STACK)) == 0) {
        H5Epush(ERR_STACK, __FILE__, FUNC_error_stack, __LINE__, ERR_CLS, ERR_MAJ_API, ERR_MIN_GETNUM,
                "Get number test failed, returned %d", err_num);
        goto error;
    } /* end if */

    /* In case program falls through here, close the stack and let it fail. */
    if(H5Eclose_stack(ERR_STACK) < 0)
        TEST_ERROR;

    return -1;

error:
    return -1;
} /* end error_stack() */
示例#2
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Eclose_stack
 * Signature: (J)V
 */
JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Eclose_1stack
    (JNIEnv *env, jclass cls, jlong stk_id)
{
    if (stk_id < 0) {
        h5badArgument(env, "H5Eclose_stack: invalid argument");
    } /* end if */
    else if (H5Eclose_stack((hid_t)stk_id) < 0)
        h5libraryError(env);
} /* end Java_hdf_hdf5lib_H5_H5Eclose_1stack */
示例#3
0
Exception::Exception() noexcept
{
  // FIXME: is this the best approach? Is it thread-safe?
  hid_t stack{H5Eget_current_stack()};
  // Pop all but inner-most frame, i.e., the root cause.
  H5Epop(stack, H5Eget_num(stack) - 1);
  // Get inner-most error message.
  H5Ewalk2(stack, H5E_WALK_DOWNWARD, setError, what_);
  // Free stack.
  H5Eclose_stack(stack);
}
示例#4
0
/*-------------------------------------------------------------------------
 * Function:    test_copy
 *
 * Purpose:     Test copyinging an error stack
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 * Programmer:  Allen Byrne
 *              February 18, 2010
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_copy(void)
{
    const char *err_func = "test_copy";      /* Function name for pushing error */
    const char *err_msg = "Error message";     /* Error message for pushing error */
    int         err_num;             /* Number of errors on stack */
    hid_t       estack_id;           /* Error stack ID */
    herr_t      ret;                 /* Generic return value */

    /* Push an error with a long description */
    if(H5Epush(H5E_DEFAULT, __FILE__, err_func, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, err_msg) < 0) TEST_ERROR;

    /* Check the number of errors on stack */
    err_num = H5Eget_num(H5E_DEFAULT);
    if(err_num != 1) TEST_ERROR
            
    /* Copy error stack, which clears the original */
    if((estack_id = H5Eget_current_stack()) < 0) TEST_ERROR
    
    /* Check the number of errors on stack copy */
    err_num = H5Eget_num(estack_id);
    if(err_num != 1) TEST_ERROR

    /* Check the number of errors on original stack */
    err_num = H5Eget_num(H5E_DEFAULT);
    if(err_num != 0) TEST_ERROR

    /* Put the stack copy as the default.  It closes the stack copy, too. */
    if(H5Eset_current_stack(estack_id) < 0) TEST_ERROR

    /* Check the number of errors on default stack */
    err_num = H5Eget_num(H5E_DEFAULT);
    if(err_num != 1) TEST_ERROR

    /* Try to close error stack copy.  Should fail because 
     * the current H5Eset_current_stack closes the stack to be set.*/
    H5E_BEGIN_TRY {
       ret = H5Eclose_stack(estack_id);
    } H5E_END_TRY
    if(ret >= 0) TEST_ERROR

    return(0);

error:
    return(-1);
} /* end test_copy() */
示例#5
0
/*-------------------------------------------------------------------------
 * Function:	test_create
 *
 * Purpose:	Test creating an empty error stack
 *
 * Return:	Success:	0
 *		Failure:	-1
 *
 * Programmer:	Quincey Koziol
 *		November 1, 2007
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_create(void)
{
    const char *err_func = "test_create";      /* Function name for pushing error */
    const char *err_msg = "Error message";     /* Error message for pushing error */
    int         err_num;        /* Number of errors on stack */
    hid_t       estack_id;      /* Error stack ID */

    /* Create an empty error stack */
    if((estack_id = H5Ecreate_stack()) < 0) TEST_ERROR

    /* Check the number of errors on stack */
    err_num = H5Eget_num(estack_id);
    if(err_num != 0) TEST_ERROR

    /* Push an error with a long description */
    if(H5Epush(estack_id, __FILE__, err_func, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, err_msg) < 0) TEST_ERROR;

    /* Check the number of errors on stack */
    err_num = H5Eget_num(estack_id);
    if(err_num != 1) TEST_ERROR

    /* Clear the error stack */
    if(H5Eclear2(estack_id) < 0) TEST_ERROR

    /* Check the number of errors on stack */
    err_num = H5Eget_num(estack_id);
    if(err_num != 0) TEST_ERROR

    /* Close error stack */
    if(H5Eclose_stack(estack_id) < 0) TEST_ERROR

    return(0);

error:
    return(-1);
} /* end test_create() */
示例#6
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	Test error API.
 *
 * Programmer:	Raymond Lu
 *		July 10, 2003
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t		file, fapl;
    hid_t               estack_id;
    char		filename[1024];
    const char          *FUNC_main = "main";

    HDfprintf(stderr, "   This program tests the Error API.  There're supposed to be some error messages\n");

    /* Initialize errors */
    if(init_error() < 0)
        TEST_ERROR;

    fapl = h5_fileaccess();

    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
	TEST_ERROR;

    /* Test error stack */
    if(error_stack() < 0) {
        /* Push an error onto error stack */
        if(H5Epush(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_ERRSTACK,
                "Error stack test failed") < 0) TEST_ERROR;

        /* Delete an error from the top of error stack */
        H5Epop(ERR_STACK, 1);

        /* Make sure we can use other class's major or minor errors. */
        H5Epush(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS2, ERR_MAJ_TEST, ERR_MIN_ERRSTACK,
                "Error stack test failed");

        /* Print out the errors on stack */
        dump_error(ERR_STACK);

        /* Empty error stack */
        H5Eclear2(ERR_STACK);

        /* Close error stack */
        H5Eclose_stack(ERR_STACK);
    } /* end if */

    /* Test error API */
    if(test_error(file) < 0) {
        H5Epush(H5E_DEFAULT, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE,
                "Error test failed, %s", "it's wrong");
        estack_id = H5Eget_current_stack();
        H5Eprint2(estack_id, stderr);
        H5Eclose_stack(estack_id);
    } /* end if */

    /* Test pushing a very long error description */
    if(test_long_desc() < 0) TEST_ERROR;

    /* Test creating a new error stack */
    if(test_create() < 0) TEST_ERROR;

    /* Test copying a new error stack */
    if(test_copy() < 0) TEST_ERROR;

    if(H5Fclose(file) < 0) TEST_ERROR;

    /* Close error information */
    if(close_error() < 0)
        TEST_ERROR;

    /* Test error message during data reading when filter isn't registered 
     * Use default FAPL to avoid some VFD drivers by the check-vfd test because
     * the test file was pre-generated. */
    h5_fixname(DATAFILE, H5P_DEFAULT, filename, sizeof filename);
    if(test_filter_error(filename) < 0)
        TEST_ERROR;

    h5_clean_files(FILENAME, fapl);

    HDfprintf(stderr, "\nAll error API tests passed.\n");
    return 0;

error:
    HDfprintf(stderr, "\n***** ERROR TEST FAILED (real problem)! *****\n");
    return 1;
}