using try/catch/finally in CUDA

Hi all,

I’m new in cuda develop and I’m trying to use the structure try/finally, but I did not have success.

The code:

static bool InitTest() {
WORD lut = (WORD)malloc(MAX_SIZE_BYTES);
for (int i = 0; i < 225; i++)
lut[i] = i;
for (int i = 225; i < MAX_SIZE; i++)
lut[i] = 2*i;

if (cudaMemcpy(LutG,lut,MAX_SIZE_BYTES,cudaMemcpyHostToDevice) != CUDA_SUCCESS) {
  return FailureShow("InitSqrt");

} __finally {

I got the error:

error C2712: Cannot use __try in functions that require object unwinding.

If I remove the “__” from try/finally I got:

error : try block requires at least one handler

Could anyone help me?

The answer given by Jared Hoberock here:

may be of interest.