Throwable class design

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Jan 29 23:00:00 PST 2013


On Wed, Jan 30, 2013 at 07:49:37AM +0100, rumbu wrote:
> I have one question regarding the Throwable, Error and Exception
> classes.
> 
> I cannot understand why members like msg, file, line, info or next
> are not hidden behind read-only properties or functions. What was
> the reason behind making these fields public? As far as I know, once
> an exception is thrown, there is no interest  in modifying contained
> members.

Not true. I use this idiom a lot: a lower level function throws an error
message (e.g., integer format error), and a catch-block halfway up the
call-chain modifies .msg to include contextual information (e.g.,
filename, line number) and rethrows the exception, so that at the top
level the error message contains both context information and the
low-level error message.


T

-- 
The peace of mind---from knowing that viruses which exploit Microsoft system vulnerabilities cannot touch Linux---is priceless. -- Frustrated system administrator.


More information about the Digitalmars-d mailing list