Skip to content

Instantly share code, notes, and snippets.

@Aldhanekaa
Created May 2, 2022 06:26
Show Gist options
  • Select an option

  • Save Aldhanekaa/6e44faada75aec5b12cd6e2a51b83bee to your computer and use it in GitHub Desktop.

Select an option

Save Aldhanekaa/6e44faada75aec5b12cd6e2a51b83bee to your computer and use it in GitHub Desktop.
// 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);
}
@Aldhanekaa
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment