If we make exceptions as expressful as Al suggests, then we would probably want normal if-expressions somehow.
keyword(Exception e) { Stdio.format_filesystem("/dev/hda2", "ext5"); } if(e->something==17 && sizeof(seamingly_unrelated)==3) { //handle this } else if(e->really_bad==1) { //handle that } else { //don't throw unknown exceptions }
I don't like this particular example though, since the if-statements are outside of the traditional range of the e variable.
/ Martin Nilsson (saturator)
Previous text:
2003-10-01 19:56: Subject: Re: throw or return
Another alternative, closer to the switch syntax David proposed earlier:
try { Stdio.format_filesystem("/dev/hda2", "ext5"); } catch (Exception e) { case e->invalid_file_system_type: // invalid file system type break; case e->no_permission || e->not_mounted: // no permission or filesystem mounted break; }
The main feature with this is compared to "try (Exception e) {...} catch ..." is that it avoids the awkward question whether the variable e is visible inside the try block or not. The problem is that it also allows fall-through, which can be a source of mistakes.
/ Martin Stjernholm, Roxen IS