Martin Olsson schrieb: > [...] > One thing I really miss from C# is stack traces printed to the terminal > when an exception occurs. > > * Would this be hard to add for Vala? > * What kind of infrastructure is needed before this can be implemented > in a _robust_ way? > [...]
Hello, strictly speaking, it is impossible to add, since Vala doesn't support exceptions, only syntactic sugar for GError handling. When a C / Vala / whatever program signals a GError, the signalling function *returns* (usually a special value) and sets the value of a special output parameter. If the error is propagated through multiple calls, all the functions up to the one that decides to handle the error return in that way. Therefore, at the point your error handler gets to see the error object, the stack trace leading to the point where the error was signalled is no longer available. To support stack traces, the g_set_error function from GLib would have to be modified such that it associates its own stack trace with the error object that it creates. However, you may want to have a look at the functions g_on_error_stack_trace from GLib [1], which is bound in Vala as GLib.on_error_stack_trace, or backtrace and friends from the GNU C library [2]. Using these you can get stack traces for C programs compiled with debugging information in a not completely unportable way ;-) Using the latter set of functions you could even write replacement code for g_set_error that stuffs a stack trace in the error message and signals a GError and using some dynamic linker magic (LD_PRELOAD=...) or textual substitution in the C code generated by Vala you could even trick your Vala programs to use that replacement instead of g_set_error while you are developing. cu, Thomas [1] http://library.gnome.org/devel/glib/2.18/glib-Warnings-and-Assertions.html#g-on-error-stack-trace [2] http://www.gnu.org/software/libtool/manual/libc/Backtraces.html _______________________________________________ Vala-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/vala-list
