I would favor a solution where "catch" didn't have to change semantics.
/ Martin Nilsson (saturator)
Previous text:
2003-10-01 18:09: Subject: Re: throw or return
A better exception system has been on the wish list for a long time. I agree that changing the errno stuff to exceptions before we have that would be a mistake. Any takers to do something about it?
I think a more "pike:ish" way to implement it is to use recognition constants instead of type inference. That makes it simpler to fix correct exception objects in dynamic environments, and it follows the "looks-like" rather than "is-a" philosophy of type comparisons in Pike.
Anyway, the difference from your proposal would be mostly syntactic in practice:
try (Exception e) { Stdio.format_filesystem("/dev/hda2", "ext5"); } catch (e->invalid_file_system_type) { // invalid file system type } catch (e->no_permission || e->not_mounted) { // no permission or filesystem mounted }
Note that the exception variable is specified in the try clause, much like how foreach variables are specified or declared in foreach clauses. The catch clauses take normal expressions, which means full freedom in writing complex catch conditions.
One could perhaps support a shorthand syntax to avoid handling the exception object explicitly:
try { Stdio.format_filesystem("/dev/hda2", "ext5"); } catch invalid_file_system_type { // invalid file system type } catch no_permission, not_mounted { // no permission or filesystem mounted }
/ Martin Stjernholm, Roxen IS