[fpc-devel] Avoid exception if FPHTTPClient cannot connect to server?

Michael Van Canneyt michael at freepascal.org
Mon Jul 31 15:27:41 CEST 2017



On Mon, 31 Jul 2017, Werner Pamler wrote:

> Agreed. This is the same situation as with string-to-number conversion: 
> StrToFloat fires an exception if the string is not a valid float, but 
> there's also a "TryStrToFloat" which by-passes the exception and just 
> returns a false in case of an error. Why not having something like a 
> "TryGet" which returns true only if the file is successfully downloaded 
> and false in all other cases (HTTP error, or no connection)?

Because that would require to completely change the interface and possibly
implementation of underlying/intermediate methods, which rely now on an 
exception being thrown.

It's of course possibly to make a TryGet which calls get and catches the exception,
but you can make such a function yourself, I really don't see the value:
in my experience, you usually want to know why the call failed, and then the 
exception is useful. A boolean value of 'false' is not very descriptive.

Michael.



More information about the fpc-devel mailing list