Skip to content
Back to skills

Error Handling

ASecurity

Exception classes, failure classes, Either type, and error handling strategies

  • 10 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added February 10, 2026
development

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add Kaakati/rails-enterprise-dev --skill error-handling --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Error Handling?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Error Handling
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/kaakati-error-handling/badge)](https://www.skillsdirectory.com/skills/kaakati-error-handling)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: "Error Handling Patterns"
description: "Exception classes, failure classes, Either type, and error handling strategies"
version: "1.0.0"
---

# Error Handling Patterns

## Exception Classes (Data Layer)

```dart
abstract class AppException implements Exception {
  final String message;
  final String? code;
  
  const AppException({required this.message, this.code});
}

class ServerException extends AppException {
  final int? statusCode;
  
  const ServerException({
    required super.message,
    super.code,
    this.statusCode,
  });
}

class CacheException extends AppException {
  const CacheException({required super.message, super.code});
}

class NetworkException extends AppException {
  const NetworkException({
    super.message = 'No internet connection',
    super.code,
  });
}
```

## Failure Classes (Domain Layer)

```dart
import 'package:equatable/equatable.dart';

abstract class Failure extends Equatable {
  final String message;
  
  const Failure(this.message);
  
  @override
  List<Object> get props => [message];
}

class ServerFailure extends Failure {
  const ServerFailure(super.message);
}

class CacheFailure extends Failure {
  const CacheFailure(super.message);
}

class NetworkFailure extends Failure {
  const NetworkFailure([super.message = 'No internet connection']);
}
```

## Either Type Usage

```dart
import 'package:dartz/dartz.dart';

// Repository returns Either<Failure, Entity>
Future<Either<Failure, User>> getUser(String id) async {
  try {
    final model = await provider.fetchUser(id);
    return Right(model.toEntity());
  } on ServerException catch (e) {
    return Left(ServerFailure(e.message));
  } on NetworkException {
    return Left(NetworkFailure());
  }
}

// Controller handles Either result
final result = await getUserUseCase('123');
result.fold(
  (failure) => _handleError(failure),
  (user) => _user.value = user,
);
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.