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() {
Box* value = threading::cur_thread_state.exc_value;
if (value) {
RELEASE_ASSERT(threading::cur_thread_state.exc_traceback == NULL, "unsupported");
// This doesn't seem like the right behavior...
if (value->cls != threading::cur_thread_state.exc_type) {
if (value->cls == tuple_cls)
Box* _type = threading::cur_thread_state.exc_type;
BoxedClass* type = static_cast<BoxedClass*>(_type);
assert(isInstance(_type, type_cls) && isSubclass(static_cast<BoxedClass*>(type), BaseException)
&& "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,
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
= runtimeCall(threading::cur_thread_state.exc_type, ArgPassSpec(1), value, NULL, NULL, NULL, NULL);
}
}
RELEASE_ASSERT(value->cls == threading::cur_thread_state.exc_type, "unsupported");
RELEASE_ASSERT(value->cls == type, "unsupported");
PyErr_Clear();
throw value;
raiseExc(value);
}
}
......
......@@ -272,11 +272,7 @@ void raiseExcHelper(BoxedClass* cls, const char* msg, ...) {
std::string formatException(Box* b) {
const std::string* name = getTypeName(b);
Box* attr = b->getattr("message");
if (attr == nullptr)
return *name;
BoxedString* r = strOrNull(attr);
BoxedString* r = strOrNull(b);
if (!r)
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