CurlDotNet

CurlDotNet.Exceptions

CurlException Class

Base exception for all curl operations. This is the base class for all curl-specific exceptions.

public class CurlException : System.Exception

Inheritance System.Object 🡒 System.Exception 🡒 CurlException

Derived
CurlFtpException
CurlAbortedByCallbackException
CurlAuthenticationException
CurlBadContentEncodingException
CurlBadDownloadResumeException
CurlBadFunctionArgumentException
CurlConnectionException
CurlCookieException
CurlCouldntConnectException
CurlCouldntResolveHostException
CurlCouldntResolveProxyException
CurlExecutionException
CurlFailedInitException
CurlFileCouldntReadException
CurlFileException
CurlFileSizeExceededException
CurlFtpAcceptFailedException
CurlFtpException
CurlFtpWeirdPassReplyException
CurlFunctionNotFoundException
CurlGotNothingException
CurlHttpException
CurlHttpPostErrorException
CurlInterfaceFailedException
CurlInvalidCommandException
CurlMalformedUrlException
CurlNotBuiltInException
CurlNotSupportedException
CurlOutOfMemoryException
CurlParsingException
CurlReadErrorException
CurlReceiveErrorException
CurlRedirectException
CurlRemoteAccessDeniedException
CurlRetryException
CurlSendErrorException
CurlSslException
CurlTimeoutException
CurlTooManyRedirectsException
CurlUnsupportedProtocolException
CurlUploadFailedException
CurlWeirdServerReplyException
CurlWriteErrorException

Example

try
{
    var result = await curl.ExecuteAsync("curl https://api.example.com");
}
catch (CurlConnectionException ex)
{
    // Handle connection-specific issues
    Console.WriteLine($"Failed to connect to {ex.Host}:{ex.Port}");
}
catch (CurlException ex)
{
    // Handle any other curl error
    Console.WriteLine($"Curl failed: {ex.Message}");
    Console.WriteLine($"Command: {ex.Command}");
    Console.WriteLine($"Error code: {ex.CurlErrorCode}");
}

Remarks

This exception provides common properties for all curl errors including the command that was executed and the curl error code.

Curl error codes match the original curl error codes from the C implementation.

AI-Usage: Catch this exception type to handle any curl-related error generically.

AI-Pattern: Use specific derived exceptions for targeted error handling.

Constructors
CurlException(string, int, string) Initializes a new instance of the CurlException class with a curl error code.
CurlException(string, string, Exception) Initializes a new instance of the CurlException class with a specified error message.
CurlException(SerializationInfo, StreamingContext) Initializes a new instance of the CurlException class with serialized data.
Properties
Command Gets the curl command that was being executed when the exception occurred.
Context Gets additional context information added via fluent methods.
CurlErrorCode Gets the curl error code matching the original curl implementation.
DiagnosticInfo Gets or sets custom diagnostic information.
Suggestions Gets suggestions for resolving this error.
Methods
GetCurlErrorName() Get the CURLE_* constant name for the error code.
GetDiagnosticInfo() Get diagnostic information for debugging.
GetObjectData(SerializationInfo, StreamingContext) Sets the System.Runtime.Serialization.SerializationInfo with information about the exception.
IsRetryable() Check if this error is potentially retryable.
Log(Action<string,Dictionary<string,object>>) Log this exception with structured data.
ToDetailedString() Get a detailed string representation of the exception.
ToJson() Get the exception as a structured JSON object for logging.
ToUserFriendlyMessage() Create a user-friendly error message.
WithContext(string, object) Add contextual information to the exception (fluent).
WithContext(Dictionary<string,object>) Add multiple context values (fluent).
WithDiagnostics(string) Add diagnostic information (fluent).
WithSuggestion(string) Add a suggestion for resolving this error (fluent).

About This Documentation

💎 Sponsored by IronSoftware - Enterprise .NET components trusted by thousands of developers worldwide.

✍️ Written by Jacob Mellor, CTO at IronSoftware.

📦 Get CurlDotNet: NuGet Package | GitHub Repository