Created
May 2, 2022 06:26
-
-
Save Aldhanekaa/6e44faada75aec5b12cd6e2a51b83bee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // library exception; | |
| typedef VoidFunction = void Function(); | |
| class ExceptionOnMessage { | |
| final String message; | |
| const ExceptionOnMessage(this.message); | |
| } | |
| abstract class Logger { | |
| void logException(Type t, [String? msg]) { | |
| print("TYPE ERROR $t: ${msg??msg}"); | |
| } | |
| void doneLogging(); | |
| } | |
| void untrustworthy() { | |
| throw Exception("d"); | |
| } | |
| void tryFunction(VoidFunction untrustworthy, Logger logger) { | |
| try { | |
| untrustworthy(); | |
| } on ExceptionOnMessage catch (e) { | |
| logger.logException(e.runtimeType, e.message); | |
| } on Exception { | |
| print("EXCEPTION ERR"); | |
| logger.logException(Exception); | |
| } finally { | |
| logger.doneLogging(); | |
| } | |
| } | |
| class B { | |
| static late final int _n; | |
| } | |
| class A extends Logger implements B { | |
| @override | |
| void doneLogging() { | |
| _n = 1; | |
| // TODO: implement doneLogging | |
| print("DONE LOGGING, the value of n: $_n"); | |
| } | |
| @override | |
| static late int _n; | |
| } | |
| void main(List<String> args) { | |
| final a = A(); | |
| tryFunction(untrustworthy, a); | |
| print(a); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Extends, used to make instance and derive from a class. It's copy the content of super-class (derived class)
read more: https://medium.com/@manoelsrs/dart-extends-vs-implements-vs-with-b070f9637b36