General considerations
According to MSDN, __try
and __except
are extensions to the C language. As such, they are not portable out of the box.
For some applications it might be possible to mimic their behaviour using macros and a setjmp
/longjmp
constructs. In general this will not be the case. In particular, MSDN states that
The __except
expression executes in the scope of the __try
body.
which cannot be achieved using macros alone.
Your questions
are __try
and __except
valid sentences in gcc?
No, they are not, as gcc does not support this Microsoft dialect of C.
are __try and __except portable sentences on *nux environments?
No, they are not, although there are ways to achieve similar exception handling on *nix as well.
do exist a better mode than __try and __except sentences for exception handling in C?
There is a strong reason to use C++ when you do exception handling. C++ scoped objects with destructors are much more robust in the presence of exceptions than standard C resource management. So while there are implementations which provide try
and catch
for C one way or another, I'd advise against them and favor C++ instead. Exception handling in C++ is part of the standard and therefore supported by all standards-compliant compilers, without portability issues.