Jump to content
Tommi Prami

Good example of what exceptions TIdHTTP cielt can raise

Recommended Posts

I was pondering that if some one has good list of exceptions to catch and what these exactly mean, it would help, so no need to go through the code to find out. 

I mean that if I have no something like 
on E: Exception do
  ...


I would prefer something like that (obviously just made up an example) 
on E:EIdSomethingSomethins do
  // Internet is most likely down

on E:EIdTimeout do
  // Server did not respond, is could not connect 
on E :IdReadTimeOut do 
  // Connected but could not read data
...
Else
  Raise

etc..

So I could more precisely catch all internet related exceptions and give more exact error messages.  I've done something like that in the past but it was more than less cumulated info over time and not always very well analyzed, I think.

I bet if someone have good exception handler and post here, and have some peer review and suggestions, we could have good starting point for all that want to do something similar
 

Share this post


Link to post
10 hours ago, Tommi Prami said:

I was pondering that if some one has good list of exceptions to catch and what these exactly mean, it would help, so no need to go through the code to find out. 

Indy has a few hundred unique exception classes defined, so it is not really feasible to give you a comprehensive list of them all.  However, most of them are specialized to specific components only, so you don't have to worry about most of them.

 

All Indy exceptions are derived from EIdException.  And then for TIdHTTP specifically, you could potentially get any of the following derived exceptions raised (this is not an exhaustive list, there might be others I missed):

  • EIdHTTPProtocolException (HTTP error response from server)
  • EIdUnknownProtocol (requesting a non-HTTP/S URL with no target port specified)
  • EIdIOHandlerPropInvalid (requesting HTTPS URL but no SSLIOHandler is assigned)
  • EIdReadTimeout
  • EIdSocketError (base class for all socket-related exceptions, may also be raised as-is)
  • EIdInternetPermissionNeeded (Android only, for now)
  • EIdConnClosedGracefully
  • EIdClosedSocket
  • EIdNotConnected
  • EIdNotASocket
10 hours ago, Tommi Prami said:

So I could more precisely catch all internet related exceptions and give more exact error messages.

What is wrong with just catching Exception/EIdException and displaying its Message property?  Mosst Indy exceptions have message texts assigned to them.

Share this post


Link to post
On 8/11/2022 at 6:54 PM, Remy Lebeau said:

What is wrong with just catching Exception/EIdException and displaying its Message property?  Mosst Indy exceptions have message texts assigned to them.

Giving own message, or having certain flow. Exception messages usually are not super good to show for users, because they are bit too technical. 

 

That's all.

 

-Tee-

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×