6 Replies Latest reply on Jan 21, 2011 6:51 PM by Meteorhead

    intellisense and error handling

    Meteorhead
      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.

        • intellisense and error handling
          LeeHowes

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

            • intellisense and error handling
              Meteorhead

              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.

                • intellisense and error handling
                  rick.weber

                  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.

                    • intellisense and error handling
                      Meteorhead

                      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(...);