- \ref GRAS_tut_tour_exceptions_intro
- \ref GRAS_tut_tour_exceptions_use
- \ref GRAS_tut_tour_exceptions_recap
-
+
<hr>
\section GRAS_tut_tour_exceptions_intro Introduction
exception in C but only in C++, Java and such. This is true, exceptions are
not part of the C language, but this is such a great tool that we
implemented an exception mecanism as part of the SimGrid library (with
-setjmp and longjmp, for the curious).
+setjmp and longjmp, for the curious).
Being "home-grown" make our exception mecanic both stronger and weaker at
the same time. First it is weaker because, well, we are more limitated
\verbatim THROWF(system_error, 0, "Cannot connect to %s:%d because of %s", hostname, port, reason);\endverbatim
Then, you simply add a #TRY/#CATCH block around your code:
-\verbatim TRY{
- /* your code */
+\verbatim TRY{
+ /* your code */
}
CATCH(e) {
/* error handling code */
So, as you can see, you don't want to include large sections of your program
in TRY blocks. If you do so, it's quite sure that one day, you'll do a break
or a return within this block. And believe me, finding such typos is a real
-pain.
+pain.
If you are suspecting this kind of error, I made a little script for you:
check <tt>tools/xbt_exception_checker</tt> from the CVS. Given a set of C
kill message to each ports of the search range. If it manage to close the
socket after sending the message without being interrupted by an exception,
it can assume that it killed the server and stop searching.
-\don'tinclude 08-exceptions.c
+\dontinclude 08-exceptions.c
\skip port=3000
\until end_of_loop
look like when it's not catched), we add a potential command line argument
to the server, asking it to cheat and to not open its port within the search
range but elsewhere:
-\don'tinclude 08-exceptions.c
+\dontinclude 08-exceptions.c
\skip strcmp
\until gras_socket_my_port
\until }
like a JVM would do (ok, it'a a bit cruder than the one of the JVM, but
anyway). For each function frame of the calling stack, it displays the
function name and its location in the source files (if it manage to retrieve
-it). Don't be jalous, you can display such stacks wherever you want with
+it). Don't be jalous, you can display such stacks wherever you want with
xbt_backtrace_display() ;)
Unfortunately, this feature is only offered under Linux for now since I have