1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-03 00:26:59 +02:00

Improve error module.

Add functions to convert error codes to C errors and handle system errors.
This commit is contained in:
David Steele
2018-01-16 13:29:27 -05:00
parent bffc6c49b3
commit 8f81620b9f
8 changed files with 150 additions and 4 deletions

View File

@ -173,4 +173,50 @@ void testRun()
assert(!testTryRecurseCatch);
assert(testTryRecurseFinally);
}
// -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("THROW_CODE()"))
{
TRY_BEGIN()
{
THROW_CODE(25, "message");
}
CATCH_ANY()
{
assert(errorCode() == 25);
assert(strcmp(errorMessage(), "message") == 0);
}
TRY_END();
// -------------------------------------------------------------------------------------------------------------------------
TRY_BEGIN()
{
THROW_CODE(777, "message");
}
CATCH_ANY()
{
assert(errorCode() == AssertError.code);
assert(strcmp(errorMessage(), "could not find error type for code '777'") == 0);
}
TRY_END();
}
// -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("THROW_ON_SYS_ERROR()"))
{
THROW_ON_SYS_ERROR(0, AssertError, "message");
TRY_BEGIN()
{
errno = E2BIG;
THROW_ON_SYS_ERROR(1, AssertError, "message");
}
CATCH_ANY()
{
printf("%s\n", errorMessage());
assert(errorCode() == AssertError.code);
assert(strcmp(errorMessage(), "message: [7] Argument list too long") == 0);
}
TRY_END();
}
}