CurlDotNet
CurlDotNet.Exceptions
CurlConnectionException Class
Thrown when a network connection cannot be established to the target host.
public class CurlConnectionException : CurlDotNet.Exceptions.CurlException
Inheritance System.Object 🡒 System.Exception 🡒 CurlException 🡒 CurlConnectionException
Derived
↳ CurlDnsException
↳ CurlProxyException
Example
try
{
var result = await curl.ExecuteAsync("curl https://internal-server:8443/api");
}
catch (CurlDnsException ex)
{
// DNS couldn't resolve the hostname
Console.WriteLine($"DNS lookup failed for {ex.Host}");
// Try fallback server
result = await curl.ExecuteAsync("curl https://backup-server/api");
}
catch (CurlConnectionException ex)
{
// Connection failed but DNS worked
Console.WriteLine($"Cannot connect to {ex.Host}:{ex.Port}");
Console.WriteLine("Check if the service is running and firewall rules");
}
Remarks
This exception indicates network-level connection failures, not HTTP errors.
Common causes include: host unreachable, port closed, firewall blocking, network timeout.
AI-Usage: Catch this to implement retry logic or fallback servers.
AI-Pattern: Check Host and Port properties to log connection details.
| Constructors | |
|---|---|
| CurlConnectionException(string, int, string, Nullable<int>, string) | Initializes a new instance of the CurlConnectionException class with an error code. |
| CurlConnectionException(string, string, Nullable<int>, string) | Initializes a new instance of the CurlConnectionException class. |
| CurlConnectionException(SerializationInfo, StreamingContext) | Initializes a new instance with serialized data. |
| Properties | |
|---|---|
| Host | Gets the host that could not be connected to. |
| Port | Gets the port number that was attempted. |
| Methods | |
|---|---|
| GetObjectData(SerializationInfo, StreamingContext) | Sets the System.Runtime.Serialization.SerializationInfo with information about the exception. |