platform/packages/pipeline/example/error_handling.dart

24 lines
619 B
Dart
Raw Permalink Normal View History

2024-12-30 09:38:18 +00:00
import 'package:platform_pipeline/pipeline.dart';
import 'package:platform_container/container.dart';
import 'package:platform_container/mirrors.dart';
2024-12-30 09:38:18 +00:00
class ErrorPipe {
dynamic handle(dynamic input, Function next) {
throw Exception('Simulated error in pipeline');
2024-12-30 09:38:18 +00:00
}
}
void main() async {
var container = Container(MirrorsReflector());
var pipeline = Pipeline(container);
2024-12-30 09:38:18 +00:00
try {
var result = await pipeline.send('World').through([ErrorPipe()]).then(
(result) => result.toString().toUpperCase());
2024-12-30 09:38:18 +00:00
print('This should not be printed');
} catch (e) {
print('Caught error: $e');
}
2024-12-30 09:38:18 +00:00
}