Add exceptions to ensure python bindings don't segfault