Exception Handler

LinkedIn Badge YouTube Badge Twitter Badge


Exception Handler

Exception Handler is a Dart package that provides a simple and flexible way to handle exceptions in your Dart/Flutter applications. It allows users to specify which types of exceptions they want to handle and provides customizable error messages for different exception scenarios.

Features

  • Handle exceptions easily with a single function call.
  • Specify which types of exceptions to handle.
  • Customize error messages for different exception scenarios.
  • Lightweight and easy to integrate into your projects.

Installation

To use Exception Handler in your Dart/Flutter project, add the following line to your pubspec.yaml file:

dependencies:
  exception_handler: ^1.0.0

Then, run dart pub get to install the package.

Usage

Import the package into your Dart file:

import 'package:exception_handler/exception_handler.dart';

Use the handleExceptions function to handle exceptions in your code:

void main() async {
  try {
    await ExceptionHelper.handle(
      () async {
        // Code that might cause exceptions
        await signinWithGoogle();
      },
      needFirebaseAuthException: true, // Specify which exceptions to handle
      needFirebaseException: false, // Specify other exceptions to handle
    );
  } catch (e) {
    // Handle the exceptions thrown by the handleExceptions function
    print('An exception occurred: $e');
  }
}

License

This package is distributed under the GNU License. See the LICENSE file for more information.


Libraries

exception_helper