NCAR / musica

Multi-Scale Infrastructure for Chemistry Modeling
https://ncar.github.io/musica/
Apache License 2.0
6 stars 3 forks source link

Add custom error handling option #88

Closed mattldawson closed 5 months ago

mattldawson commented 5 months ago

Adds an option for users to provide a custom error handling function through the C API that will be called for any exceptions thrown by the C++ libraries.

closes #38

I'm not sure if this is the best design. I think it will work for the CAM-SIMA use case where they just want to provide a single function that gets called for any error. But, I'm not sure if a global function pointer for errors is the best solution. I don't mind changing this approach entirely if anyone has a better solution.

K20shores commented 5 months ago

The only thing I really dislike is random numbers we have to provide as the code argument. I can't think of a better way right now

mattldawson commented 5 months ago

The only thing I really dislike is random numbers we have to provide as the code argument. I can't think of a better way right now

Yeah, I agree. After more discussion and checking with the CAM-SIMA developers, I think I might redo this PR to just have the MUSICA C API functions always return an error code and message by catching any exceptions thrown in MICM. I will also explore options that don't require us to create random numbers for error codes.

mattldawson commented 5 months ago

I think this is ready for another look now. All the API functions return an error object that has a code, category, and message. The combination of the code and category can be used to identify specific errors, and there are some helper functions to do this. Let me know what you think!