Exception handling

I’m trying to compile some CUDA code and getting the following error message:

error: support for exception handling is disabled.

I took a look at the comiler options but couldn’t find out how to enable excetion handling. Can somebody help me, pls?

Are you using exceptions in your CUDA code? You are aware that nvcc is a C compiler right? It supports a few C++ extensions, and I don’t believe exceptions is one of them.

NVCC does a pretty good job at handling just about all of the craziest C++ I’ve thrown at it. Exception handling is the one exception (bad pun, I know) to this, and I for one would love to see it included at some point. The most compelling reason is so that I can include things like iostream, and other standard C++ headers that have exceptions built in.

You cannot. High level CUDA code is supposed to be C code. C++ exception handling will thus not work. The same goes for any other C++ stuff like templates etc as the C compiler will not be able to handle it. If you want to interface CUDA code with your C++ project, you need to create wrapper C++ classes in separate files that get compiled by the C++ compiler. The wrappers then simply call the C API functions.

There is a small light at the end of the C tunnel however: CUDA needs to do extensive preprocessing (to split host from device code for example). The preprocessing is done using g++ or cl. They do understand C++ so you actually can use C++ stuff that can be fully resolved at preprocessing time. Run nvcc -v to see whats going on. For example, fully specialized templates can be resolved within the preprocessing to a set of C functions, which is why they work. See the various SDK examples and toolkit headers on how to use them. Partially specialized templates or anything needing linktime/runtime information thus doesn’t work. Exceptions being one of them.


Maybe it would help if NVIDIA put some other people than the marketing department on writing the so called programming guide. It states that “fully c++” would be suppported for host code. I thought exception handling was part of “fully c++”.

pretty sure this has changed in the past year since the thread was created (which is why there’s now the “–host-compilation c++” compiler option)

IIRC I used exceptions in cu-file host code successfully. However --host-compilation c++ is essential.

Exception handling can work with “–host-compilation c++”. Open the simpleGL project from the SDK, add "#include " at the top and append --host-compilation c++ to the compiler’s command line in project properties. It works (at least for me). But I do have some problems with doing the same in my own projects (generated by kyzhao’s Wizard). The peculiar thing is if I copy the compiler’s command line visible in my own project properties, paste it into DOS console and run, it compiles. These are probably some intricacies connected more to VS2005 than to CUDA. I don’t have SP1 yet by the way.

I realize, I should have looked at the dates of the previous posts on this topic before posting…

For some reason, on my Windows system many things (like #include) started to work much better when I entered the path to Visual Studio correct (case-sensitive!) at the command line (not nvcc.profile):

nvcc -ccbin “C:\Program Files\Microsoft Visual Studio 8\VC\bin” …

instead of

nvcc -ccbin “c:\program files\microsoft visual studio 8\vc\bin” …

I am not sure whether this is a CUDA or Visual Studio bug, but the behavior is similar on at least two different systems that I tried it on (one with the express edition and one with vs professional).

just use the Visual Studio Command Prompt and you shouldn’t have to enter anything for --ccbin, which is what I do.

You mean like this?

-ccbin "$(VCInstallDir)bin"

My problem is (was) that I use Visual Studio 2008 for everything except .cu files. Therefore, I have to tell nvcc to use Visual Studio 2005 Express. For some reason this only partially (ok with most code, but strange errors with for instance #include)work by entering this option in nvcc.profile. However, since it works with -ccbin case sensitive path, I am happy. Support for Visual Studio 2008 would of coarse be nice, but this seem to take another couple of months if I understood this correctly.