How to report an error condition in a kernel?

Hello. This is a beginner’s question.

What is the accepted way to report a custom error condition detected in a kernel to the host program?
global functions can only return void and I would not expect a possibility to throw an exception.
Of course I can place an error code or message into global memory, but is there some API for it?

Write it to global memory.

Nvidia recently released an official cuPrintf() library (well, source code), but someone one this forum did something similar on their own a while back…search the forum and see if you can find it. The techniques used will be pretty similar to what you need.