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);
__try{
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 {
free(lut);
}
}

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?
Thanks.

The answer given by Jared Hoberock here:

http://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api

may be of interest.