Commit 520dd6e6 authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

Fix up some exception behavior

parent ef284133
...@@ -633,20 +633,28 @@ void checkAndThrowCAPIException() { ...@@ -633,20 +633,28 @@ void checkAndThrowCAPIException() {
Box* value = threading::cur_thread_state.exc_value; Box* value = threading::cur_thread_state.exc_value;
if (value) { if (value) {
RELEASE_ASSERT(threading::cur_thread_state.exc_traceback == NULL, "unsupported"); RELEASE_ASSERT(threading::cur_thread_state.exc_traceback == NULL, "unsupported");
Box* _type = threading::cur_thread_state.exc_type;
// This doesn't seem like the right behavior... BoxedClass* type = static_cast<BoxedClass*>(_type);
if (value->cls != threading::cur_thread_state.exc_type) { assert(isInstance(_type, type_cls) && isSubclass(static_cast<BoxedClass*>(type), BaseException)
if (value->cls == tuple_cls) && "Only support throwing subclass of BaseException for now");
// This is similar to PyErr_NormalizeException:
if (!isInstance(value, type)) {
if (value->cls == tuple_cls) {
value = runtimeCall(threading::cur_thread_state.exc_type, ArgPassSpec(0, 0, true, false), value, NULL, value = runtimeCall(threading::cur_thread_state.exc_type, ArgPassSpec(0, 0, true, false), value, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
else } else if (value == None) {
value = runtimeCall(threading::cur_thread_state.exc_type, ArgPassSpec(0), NULL, NULL, NULL, NULL, NULL);
} else {
value value
= runtimeCall(threading::cur_thread_state.exc_type, ArgPassSpec(1), value, NULL, NULL, NULL, NULL); = runtimeCall(threading::cur_thread_state.exc_type, ArgPassSpec(1), value, NULL, NULL, NULL, NULL);
} }
}
RELEASE_ASSERT(value->cls == type, "unsupported");
RELEASE_ASSERT(value->cls == threading::cur_thread_state.exc_type, "unsupported");
PyErr_Clear(); PyErr_Clear();
throw value; raiseExc(value);
} }
} }
......
...@@ -272,11 +272,7 @@ void raiseExcHelper(BoxedClass* cls, const char* msg, ...) { ...@@ -272,11 +272,7 @@ void raiseExcHelper(BoxedClass* cls, const char* msg, ...) {
std::string formatException(Box* b) { std::string formatException(Box* b) {
const std::string* name = getTypeName(b); const std::string* name = getTypeName(b);
Box* attr = b->getattr("message"); BoxedString* r = strOrNull(b);
if (attr == nullptr)
return *name;
BoxedString* r = strOrNull(attr);
if (!r) if (!r)
return *name; return *name;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment