Skip to content
pubscout

exception_templates

1.1.0, released 9 weeks ago by simphotonics.com

Generic Dart exception and error classes for throwing and catching custom exceptions by type argument.

WASM-ready
$ flutter pub add exception_templates
Source repository

What it does

Provides generic exception and error classes that highlight context or type, featuring colourized console output. It also includes string extension functions to validate Dart identifiers and keywords.

AI-written summary of version 1.1.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to catch exceptions based on their generic type arguments.
  • You need custom error and exception classes with colourized console output.
  • You want to validate if a string is a valid Dart identifier or keyword.

Skip it when

  • You require a complex error tracking or crash reporting system.
  • You prefer standard built-in Dart exceptions without custom formatting.

Strengths

  • Enables catching exceptions based on type arguments.
  • Includes built-in colourized console output support.
  • Provides helper extension methods for identifier validation.

Weaknesses

  • Limited to basic console formatting and generic exception wrappers.
  • No built-in localization for exception messages.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1
import 'package:exception_templates/exception_templates.dart';

class LengthMismatch extends ErrorType;

void example() {
  throw ErrorOfType<LengthMismatch>(
    message: 'Length mismatch occurred.',
    invalidState: 'Sizes do not match.',
    expectedState: 'Equal sizes.',
  );
}

Alternatives

Packages that do the same job and could replace exception_templates.

  • result_type

    A Result type representing success or failure in Dart

  • either_dart

    Type‑safe Either monad for handling errors without exceptions in Dart/Flutter.

  • type_plus

    Utility for introspecting and manipulating Dart types at runtime.

  • flutter_guid

    Emulates C# Guid in Flutter to generate UUIDs and add Guid variables to classes.

Works with

Packages commonly used together with exception_templates: ones it builds on, ones built on it, and its own family.