dotnet-error-handling

Implements exception handling for APIMatic-generated .NET SDK calls in C#.

Updated Jun 9, 2026
One-click install
npx skills add https://github.com/apimatic/plugin-marketplace --skill dotnet-error-handling-apimatic
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-error-handling
Source: https://github.com/apimatic/plugin-marketplace/tree/main/plugins/maxio-sdk/skills/dotnet-error-handling
Command: npx skills add https://github.com/apimatic/plugin-marketplace --skill dotnet-error-handling-apimatic

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Catching errors from an APIMatic-generated .NET SDK is easy to get wrong: the thrown SdkException<TError> carries either a typed per-operation error model or a raw error body, and a catch ladder written from memory silently drops responses, leaks internal type names, or misses connection failures entirely. ## Core Features & Use Cases - Two-case exception model: Distinguishes operations that throw SdkException<{Operation}Error> (typed model with TryGet* accessors) from those that throw SdkException<RawError>, with the correct namespaces and using directives for each. - Complete catch ladders: Enumerates every TryGet* accessor on the typed error model, orders TryGetRawError last, and explains why factoring error reading into an ApiError-typed helper loses typed bodies. - Non-throwing alternative: Covers the optional {Operation}Result sibling method returning ApiResult<TResponse, TError>, which exposes status codes and headers on both success and failure. - Use Case: While writing a service that calls a payments endpoint, you add a try/catch around the SDK call; the skill tells you the exact exception type to catch, every accessor branch to write, and how to convert connection failures and JSON parse failures into your own boundary error type without leaking framework details. ## Quick Start Ask the agent to write the error handling for a specific SDK operation, for example: write the try/catch for the CreateWidget call using the dotnet error handling skill.

Frequently Asked Questions about dotnet-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I catch exceptions from an APIMatic .NET SDK call?▼

Catch SdkException<TError> where TError is either the operation's typed {Operation}Error model or RawError, depending on the operation. Check the method's XML doc exception line: the type named after 'of <see cref=.../>' is the actual TError to catch.

How do I read the error body from a .NET SDK exception?▼

Read ex.Error directly off the strongly-typed catch. For typed error models, call each TryGet* accessor with TryGetRawError last; for RawError, use StatusCode and ReadAsString() or ReadAsJson<T>() directly.

Does the APIMatic .NET SDK support non-throwing API calls?▼

Yes, when the generator emits a {Operation}Result sibling method returning ApiResult<TResponse, TError>. It does not throw on non-success statuses and exposes StatusCode and Headers on both success and failure, but it is optional and may not exist for every operation.

Why does my catch of SdkException miss connection failures?▼

SdkException only covers non-2xx API responses. Connection failures like DNS errors or timeouts surface as HttpRequestException or TaskCanceledException, which require a separate catch clause at your boundary.

Why does my typed catch never fire for some error responses?▼

If the generated error model disagrees with the actual response body, deserialization throws a JsonException while constructing the error object, replacing the SdkException. Catch JsonException separately and map it distinctly from success-path parse failures.