[Box Backup] Exception handling (was: Win32 port (was: BoxBackup Server Side Management Specs (Draft0.01)))

Ben Summers boxbackup@fluffy.co.uk
Sun, 3 Oct 2004 14:04:44 +0100


On 2 Oct 2004, at 23:43, Chris Wilson wrote:

> Hi Ben,
>
>> So far I have not needed to change any code, and I hope that I can
>> maintain the Windows GUI semi-independently, only relying on some 
>> header
>> files from Box. However, there does seem to be a fair amount of
>> auto-generated and platform-dependent stuff that might require work 
>> on the
>> build system to integrate properly. I will tackle that when I have
>> something worth integrating :-)
>
> I just added a virtual null declaration of what() to BoxException, 
> since
> all the subclasses seem to implement it, and it's extremely useful. I
> could send you a patch, but it would be against 0.07 release, and it's
> trivial:
>
> +++ lib/common/BoxException.h
> @@ 70,1
> +	virtual const char *what() const throw() = 0;

It inherits this off std::exception, so an extra declaration is 
redundant.

>
> I would really like to see exceptions have more context information, 
> for
> example a filename in the case of an error opening a file. Perhaps the
> default constructors for BoxException and subclasses should 
> (optionally?)
> take a string to describe the context in a user-visible error message?

Yes, they could be a bit more helpful, I agree. This is all a result of 
the project's history, I'm afraid, and is on my list to tidy up in the 
future.

>
> Is there a reason for implementing exceptions with various numeric 
> codes,
> rather than creating an explicit subclass for each one? I think the 
> latter
> would increase type-safety, and allow one to more easily catch an
> exception that you're expecting, while ignoring (and propagating) an
> unexpected exception.

Well... if you had a class per exception code, then that would be an 
awful lot of extra code and type information in the executable which 
isn't strictly necessary. It's not very often that you actually need to 
catch a specific exception, so this seems a good compromise between all 
the options.

Ben

PS: I hope this discussion of the code isn't off-putting to anyone -- I 
would prefer to move these discussions to a -tech mailing list that 
lose subscribers. Contact me off list with any comments!