[commit] Add "struct exception"
Andrew Cagney
cagney@gnu.org
Wed Jan 12 23:59:00 GMT 2005
If this were Java, we'd be writing:
class ErrorException extends Exception ...;
class NoSourceFileErrorException extends ErrorException ...;
...;
and then
try {
...
} catch (ErrorException e) {
System.out.println (e.toString ());
}
but it isn't so we can't.
The attached patch establishes a framework that makes it possible to
work around this limitation of C. It adds:
struct exception;
struct exception catch_exception(...)
throw_exception(struct exception)
(The existing throw_exception is renamed to throw_reason to avoid a name
clash, callers updated). This lets users write a rough equivalent:
struct exception e = catch_exceptions (....)
switch (exception.reason)
...
case ERROR_RETURN:
print (exception.message);
and even opens the possibility of:
TRY_CATCH (e)
{
...
}
switch (e.reason)
...
The hacks error_silent and error_last_message can now be eliminated.
exceptions.[hc]'s has been rewritten to use it; tested on ppc gnu/linux.
committed,
Andrew
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: diffs
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20050112/b7578add/attachment.ksh>
More information about the Gdb-patches
mailing list