Search code examples
halide

How to handle errors at runtime in halide?


In case of Ahead of Time compilation, How can I make Halide to throw exceptions which could be handled at a higher call stack? Say for example when an input image is accessed at an incorrect location.


Solution

  • You can call halide_set_error_handler to install your own error handling routine. (Or override halide_error directly if on a platform that supports weak linking.) Your own error handler can throw an exception. It isn't the most tested part of Halide, but we do intend to allow the error routine to throw an exception that is handled higher up on the call stack than the call the the Halide compiled code. All memory allocations, etc. should be freed via scoped destructors.