On 10/2/14 2:45 AM, Jacob Carlborg wrote:
On 01/10/14 21:57, Steven Schveighoffer wrote:

./progThatExpectsFilename ""

-Steve

It's the developer's responsibility to make sure a value like that never
reaches the "File" constructor. That is, the developer of the
"progThatExpectsFilename" application that uses "File". Not the
developer of "File".

Then what is the point of File's constructor throwing an exception? This means, File is checking the filename, and I have to also check the file name.

Although, I don't see why you shouldn't be able to pass an empty string
to "File". You'll just get an exception, "cannot open file ''".

Right, that is fine. If you catch the exception and handle the result with a nice message to the user, that is exactly what should happen.

If you forget to catch the exception, this is a bug, and the program should crash with an appropriate stack trace.

Note 2 things:

1. You should NOT depend on the stack trace/Exception to be your error message. 2. File's ctor has NO IDEA whether throwing an exception is going to be a bug or a handled error condition.

I would say, as soon as an exception is thrown and is not caught by user code, for all intents and purposes, it becomes an Error.

-Steve

Reply via email to