cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Meteorhead
Challenger

intellisense and error handling

programming facilitation

Hi all!

I got two questions. First is, is there any way to get intellisense inside kernels, or if not, are there plans to achieve this?

Second is, has anyone found a neat way to get rid of extensive error handling? I was hoping the C++ wrapper would have some overridable error handling function inside all objects that one could change according to needs, but the C++ functions return with the same error codes that have to be taken care of with yet another function (which makes all API calls two lines). It does make reading code a lot harder.

Eager to listen to all ideas.

0 Likes
6 Replies
LeeHowes
Staff

That's what exceptions are for, really. Catch the exception just once at the bottom of the code after a sequence of API calls.

0 Likes

I'm not that familiar with using exceptions, but if I'm not mistaken that implies that only one exception occurs in the given series of API calls, and more importatntly, the last will be visible to the user and not the first one.

0 Likes

Consider the following:

try
{
  a();
  b();
  c();
}
catch(exception& e)
{
  cout << e.what();
}

In this code, the catch statement handles the error, regardless of whether or not a, b, or c threw the exception. Unfortunately, it's often hard to diagnose exactly which function the error came from, unless a, b, c throw different kinds of exceptions and you have a catch statement for each one or you put try catch around a, b, c individually. In the first case and the example given, the first (and only first) exception is visible to the user since the catch block is called immediately when any exception is thrown and then the code continues after the catch.

My clUtil library handles errors in a simpler way that makes debugging easier: it calls a macro to check that err == CL_SUCCESS. If not, it looks up the error code as a string; prints the file, line number, and error; and raises SIGTRAP. This way, if you run your application in a debugger, it immediately breaks on the line after the error. If you just run your application and get an error, it prints the file and line number in clUtil where the error occurred.

0 Likes

I was thinking of creating a CLerror class and overload it's = operator so that if it sees a cl_int as right hand argument, it runs whatever error handling routine I want to create. This way API calls would simply look like the attached code.

Only problem with this is that some API calls do not return the error output, but they ask for them as a reference argument.

I was thinking of somehow taking care of this with a macro, but if anyone knows a neat way, please let me know. Rick's solution is good, but I have no idea how I could implement it. (Get the line number of the source code for eg.)

CLerror CL_err; CL_err = clSetKernelArgument(...);

0 Likes

I do this:

printf(%s:%d: %s, __FILE__, __LINE__, clUtilGetError(err))

There's also the __func__ macro in C99 that returns a string containing the current function name. By putting this in a macro, the file and line numbers get filled in by the compiler at each call site.

0 Likes

Thanks a lot, I guess I'll manage from here.

0 Likes