Skip to content

Instantly share code, notes, and snippets.

@psygo
Last active May 17, 2020 20:50
Show Gist options
  • Save psygo/58783a6caa08e89b5df3f1553c08e7fa to your computer and use it in GitHub Desktop.
Save psygo/58783a6caa08e89b5df3f1553c08e7fa to your computer and use it in GitHub Desktop.
An exception template which you can extend (inheritance... since `Exceptions` typically have the same implementations)
import 'package:meta/meta.dart';
// import 'package:flutter/foundation.dart'; // Alternative for Flutter
@immutable
abstract class CustomizableException implements Exception {
static const String blankMsg = '';
static const String divider = ': ';
final String msg;
const CustomizableException([msg]): msg = msg ?? blankMsg;
@override
String toString() => '$runtimeType$divider$msg';
}
@immutable
class CustomException extends CustomizableException {
const CustomException([msg]): super(msg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment