Swift Error Handling
Installation
SKILL.md
Swift Error Handling
Priority: P0
Implementation Guidelines
Throwing Functions
- Propagate Errors: Use
throwsfor recoverable errors. - Do-Catch: Handle errors close to source with specific catch blocks.
- Error Types: Define custom errors as enums conforming to
Error.
Result Type
- Async Alternatives: Use
Result<Success, Failure>for callback-based APIs. - Transformations: Use
.map(),.flatMap()for functional composition. - Conversion: Use
.get()to convertResultto throwing.
Never Type
- Fatalisms: Use
Neverreturn type for functions that never return. - Preconditions:
fatalError(),preconditionFailure()for programmer errors.
Anti-Patterns
- Force Try:
**No try!**: Use try? or do-catch. - Silent Failures:
**No try? without nil check**: Handle or log. - String Errors:
**No Error(message)**: Use typed errors.
References
Related skills
More from hoangnguyen0403/agent-skills-standard
skill creator
Standards for creating new High-Density Agent Skills with optimal token economy.
181java-language
Modern Java 21+ standards including Records, Pattern Matching, and Virtual Threads. Use when working with Java records, sealed classes, switch expressions, text blocks, Optional, or upgrading from older Java versions. (triggers: **/*.java, pom.xml, build.gradle, record, sealed, switch, var, Optional, stream, VirtualThread, instanceof, text block)
1swift swiftui
Standards for State Management, View Lifecycle, and Property Wrappers
1swift tooling
Standards for SPM, Build Configs, and Code Quality
1swift testing
Standards for XCTest, Async Tests, and Test Organization
1swift language
Standards for Optionals, Protocols, Extensions, and Type Safety
1