Possible "throws" syntax

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Aug 17 01:48:01 PDT 2012


On 17-Aug-12 11:47, Marco Leise wrote:
[snip]

>> Including but not limited to the time when foo's author adds more types
>> to his "throws list". Unlike checked exceptions it won't break build
>> just for the fuck of it *and* it will still work correctly.
>>
>> In fact if we manage to come up with proper reasonable standard
>> exceptions like Network/IO/etc. that everybody derives from error
>> handling would become damn easy with *any* library.
>

> Just for the fuck of it, huh :) ?

I'm currently working on Java project part-time (it shows :) ), a small 
app-specific server that has to pipeline work items back and forth and 
do it fast. It's damn frustrating to see (and adapt) when your colleges 
add/remove exception specs of their interface. And even I discover that 
methods get or lose throws ExceptionX frequently during development.

> Interesting read, do you know an example, probably a standard library of some other language,
that offers standard exceptions like this?

No, but it's about time to innovate. What I know for sure is that other 
failed to deliver. (C++ STL - failed, Java - see above, .NET appears to 
be in the same boat - i.e. more exceptions good and any)

> If I understand you correctly, the idea is to not use
distinct error ids (be they codes or exception classes), but a mix of 
flags.

While I think flags would be a very common way to _hint_ on how to 
correct the error (or current state of system as a whole). I do suspect 
that some error types may need more then just a flag, but who knows.

So you'd have pretty much one "catch" with a few "if"s,
but with the flags you can decide on the granularity.

Something like that. With ifs you query important properties about error 
that allow you to pick the best recover decision. The whole propose of 
flags is to unify only _important_ items for the _decision_ process and 
hide useless variability (it still goes to message).

A comic-book example:
Top scientist breaks into Mr. President room and cries:
"We are doomed! Crystal oculator was miscalculated, all readings are 
under 0.6543124312,  helerium core just melted!"

Now does it mean it's time to evacuate promptly or instead give order to 
isolate the secret lab and "end" this guy's project? Unless Mr.President 
has a nice and long lookup table of all (pseudo) scientific terms he has 
no clue.


-- 
Olshansky Dmitry


More information about the Digitalmars-d mailing list