June 08, 2006 Re: catch/rethrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | 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
|
June 08, 2006 Re: catch/rethrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to kris | 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 |
June 08, 2006 Re: catch/rethrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Pelcis | James Pelcis wrote:
> overly interrupting the program. I think the rationale is that after you have taken the time to handle an exception, why would you rethrow it?
This is very common:
connection.open();
try {
// ...
} catch {
connection.close();
throw;
}
Of course, I could replace that with the on_scope keyword.
|
Copyright © 1999-2021 by the D Language Foundation