added a pkpy_error method

This commit is contained in:
Kolten Pearson 2023-05-09 18:05:43 -06:00
parent ae34a6304a
commit ceab1e0609
5 changed files with 23 additions and 2 deletions

View File

@ -550,3 +550,12 @@ bool pkpy_push(pkpy_vm* vm_handle, int index) {
vm->c_data->push(vm->c_data->begin()[index]);
return true;
}
bool pkpy_error(pkpy_vm* vm_handle, const char* message) {
CVM* vm = (CVM*) vm_handle;
ERRHANDLER_OPEN
throw Exception("CBindingError", message);
ERRHANDLER_CLOSE
}

View File

@ -22,6 +22,13 @@ typedef struct pkpy_vm_handle pkpy_vm;
bool pkpy_clear_error(pkpy_vm*, char** message);
//NOTE you are responsible for freeing message
//this will cause the vm to enter an error state and report the given message
//when queried
//note that at the moment this is more like a panic than throwing an error
//the user will not be able to catch it with python code
bool pkpy_error(pkpy_vm*, const char* message);
pkpy_vm* pkpy_vm_create(bool use_stdio, bool enable_os);
bool pkpy_vm_run(pkpy_vm*, const char* source);
void pkpy_vm_destroy(pkpy_vm*);

View File

@ -317,6 +317,8 @@ int main(int argc, char** argv) {
//maybe worth fixing someday, but for now it is functionating as implemented
error(pkpy_vm_run(vm, "try : test_error_propagate(); except NameError : pass"));
error(pkpy_error(vm, "test direct error mechanism"));
//more complicated error handling
//

View File

@ -61,3 +61,6 @@ NameError: testing error throwing from python
successfully errored with this message:
Traceback (most recent call last):
NameError: could not find requested global
successfully errored with this message:
Traceback (most recent call last):
CBindingError: test direct error mechanism

View File

@ -19,8 +19,8 @@ echo "checking results (they should be identical)"
diff -q -s binding_test_scratch c_bindings/test_answers.txt
echo "cleaning up"
rm pocketpy_c.o
#rm pocketpy_c.o
rm test.o
rm binding_test_scratch
rm c_binding_test
#rm c_binding_test