catch/rethrow
Derek Parnell
derek at psych.ward
Wed Jun 7 18:04:08 PDT 2006
On Wed, 07 Jun 2006 17:50:09 -0700, kris wrote:
> Sean Kelly wrote:
>> You can for the above case. But D also supports:
>>
>> catch{ ... }
>>
>> ie. without the "(Exception e)". However, unlike C++, "throw;" in this
>> instance is invalid so there's no way to rethrow the exception.
>>
>> Basically, I'm wondering why this form of catch exists. It can catch
>> exceptions but not report anything about them (as it has no object
>> reference), and it can't rethrow them. I can't think of a single case
>> where I would actually use this statement as it exists now.
>
> Gotcha, and neither can I
I have this routine that I use ...
bool FileExists(char[] pFileName)
{
if (pFileName in lExistingFiles)
{
return true;
}
try {
if(std.file.isfile(pFileName) && std.file.exists(pFileName))
{
lExistingFiles[pFileName] = true;
return true;
}
} catch { };
return false;
}
The idea being that I really don't care what exception is thrown by the
called functions 'isfile' and 'exists', but if any exception is thrown then
I want to prevent the program from crashing and also inform my caller about
the information they requested - namely that the file specified doesn't
exist.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
8/06/2006 11:01:06 AM
More information about the Digitalmars-d
mailing list