Exception handling?

I’m wondering how to do the exception handling in an OpenGL programm. If i do a normal application with the vcl, i’m always handle my exceptions with the
try… catch… finally… blocks, and so… So, is it usefull or recommended to use these Exception handlers also in OpenGL???

(quiet this kind of exception handling is a C++ feature, isnt it?)

thx HECK

try/catch/throw is C++, OpenGL is C, so no, it won’t work with OpenGL.

But nothing stops you from using exception handling for your own code though. You just can’t use it for detecting/handling OpenGL-related errors.

OpenGL is C? <says to an off-camera person and mutters quitely> what kind of game is he playing at?

noooo, no no no. opengl is no such thing. opengl is just an api… it has C bindings, but it also has java, ada and fortran bindings. it’s an api, and not a langauage damnit! <said like doctor whatshisname from star trek>

cheers,
John

OpenGL implementations are often written in c…
Not sure if that is what Bob meant, though.

You can use GLGetError() to see if a GLError has been registered. Check the red book pg. 563.

Funk.

yer, so? C is compiled into machine code, so the fact they WERE C is irrelevent. In fact, some compilers—like the mighty GNU power horse—compile the source language into an intermediate code of their own design, before writing an assembler/compiler to translate the intermediate code into the target machine code. so… even something like the gnu ada compiler compiles into the SAME gnu object langauge as the gnu c compiler (as does the gnu fortran compiler)… so, what’s the difference? there is no difference.

at the end of the day, opengl is NOT a language. it doesn’t have a set of EBNF rules describing its syntax, a list of rules describing its semantics (although it has a man page for its prototypes=). it’s just not a langauge.

cheers,
John

true, true…

I wasn’t saying OpenGL is a language, just trying to clear up some confusion, guess I failed. he he…

Funk.

oh! and another thing! you can implement exception LIKE things in C with the longjmp mechanism. =)

oh, and exception handling in C++ shouldn’t affect things, greatly… uhm. no. it shouldn’t. but you have to appreciate that the opengl context is quite independent of what your program is doing, so you better make sure that the opengl context is happy. for example, if you did this:

glBegin(GL_LINES);
glVertex2f(…);
try {
doSomethingWhichMightCauseAnException();
glVertex2f(…);
} catch(int ackfatalmycodejustdied) {
glVertex2f(…);
}
glEnd();

then what is drawn on screen will be different if your exception is taken, or not. As you would excpet, that is, so long as all your glVertex calls are different.

cheers,
John

john,

I think what Bob meant is that it is unlikely that doing:

try
{
glCommand(GLparam xxx);
}
catch(xxx)
{
}

will ever lead you to the “catch” part…

And as he said, this is simply because it is very unlikely that you will find a “throw” in the implementation of “glCommand” if this glCommand has been implemented using C.

And yes, I know, you can catch C exception using C++…

Regards.

Eric

Uhm, yeah sure. OpenGL is not C, sorry. It has C bindings.

I DO know OpenGL is not a langeuage itself. Even though I might have expressed myself the other way, it was not meant to. What I was trying to point out is that OpenGL is not object oriented, and does not use any C++ specific features. And the API is therefore is more like C than C++. The C-bindings that is.

And the example Eric gave about using try/catch, was about what I meant. Sure, you CAN code that way, but you shouldn’t expect the catch-part to be executed that much.