Fixed error dispatching bug; consolidated catches

This commit is contained in:
BLM 2015-07-27 13:43:34 -05:00
parent dd3253e109
commit 51cf4a0fff
2 changed files with 29 additions and 34 deletions

View File

@ -39,7 +39,7 @@ void reportOutOfMemory() {
void reportException(const std::exception& exception) { void reportException(const std::exception& exception) {
{ {
const std::bad_alloc* bad_alloc = reinterpret_cast<const std::bad_alloc*>(&exception); const std::bad_alloc* bad_alloc = dynamic_cast<const std::bad_alloc*>(&exception);
if(bad_alloc != nullptr) { if(bad_alloc != nullptr) {
reportOutOfMemory(); reportOutOfMemory();
return; return;

View File

@ -36,8 +36,7 @@ static char* textToCString(const text* text) {
//Internal function used by phone_number_in and parse_phone_number //Internal function used by phone_number_in and parse_phone_number
//TODO: take a std::string to minimize copying? //TODO: take a std::string to minimize copying?
ShortPhoneNumber* parsePhoneNumber(const char* number_str, const char* country) throw() { ShortPhoneNumber* parsePhoneNumber(const char* number_str, const char* country) {
try {
PhoneNumber number; PhoneNumber number;
ShortPhoneNumber* short_number; ShortPhoneNumber* short_number;
@ -57,14 +56,6 @@ ShortPhoneNumber* parsePhoneNumber(const char* number_str, const char* country)
return nullptr; return nullptr;
} }
//TODO: check number validity. //TODO: check number validity.
//TODO: figure out why we need this.
} catch(const PhoneNumberTooLongException& e) {
reportException(e);
} catch(const std::exception& e) {
reportException(e);
}
return nullptr;
} }
//TODO: check null args (PG_ARGISNULL) and make non-strict? //TODO: check null args (PG_ARGISNULL) and make non-strict?
@ -82,6 +73,7 @@ extern "C" {
PGDLLEXPORT Datum PGDLLEXPORT Datum
phone_number_in(PG_FUNCTION_ARGS) { phone_number_in(PG_FUNCTION_ARGS) {
try {
const char *number_str = PG_GETARG_CSTRING(0); const char *number_str = PG_GETARG_CSTRING(0);
//TODO: use international format instead. //TODO: use international format instead.
@ -91,6 +83,9 @@ extern "C" {
} else { } else {
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
} catch(std::exception& e) {
reportException(e);
}
} }
PGDLLEXPORT PG_FUNCTION_INFO_V1(parse_phone_number); PGDLLEXPORT PG_FUNCTION_INFO_V1(parse_phone_number);