Skip to content

IOSink.add throws exceptions that cannot be caught #48501

@Hixie

Description

@Hixie

How do I catch the exception thrown in the code below?

import 'dart:io';

void main() async {
  try {
    final Process process = await Process.start('echo', <String>[]);
    process.stdin.add([1,2,3]); // throws an exception                                                                                            
  } catch (error) {
    print('$error\n'); // does not catch it... :-(                                                                                                
  }
}

For the record the exception I'm talking about is:

Unhandled exception:
SocketException: Write failed (OS Error: Broken pipe, errno = 32), port = 0
#0      _NativeSocket.write (dart:io-patch/socket_patch.dart:1190:34)
#1      _RawSocket.write (dart:io-patch/socket_patch.dart:1906:15)
#2      _Socket._write (dart:io-patch/socket_patch.dart:2346:18)
#3      _SocketStreamConsumer.write (dart:io-patch/socket_patch.dart:2094:26)
#4      _SocketStreamConsumer.addStream.<anonymous closure> (dart:io-patch/socket_patch.dart:2068:11)
#5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1618:10)
#6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#8      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
#9      _StreamController._add (dart:async/stream_controller.dart:648:7)
#10     _StreamController.add (dart:async/stream_controller.dart:596:5)
#11     _StreamSinkImpl.add (dart:io/io_sink.dart:136:17)
#12     _Socket.add (dart:io-patch/socket_patch.dart:2193:38)
#13     _StdSink.add (dart:io/stdio.dart:327:11)
#14     main (file:///home/ianh/dev/dsh/example/test.dart:6:19)
<asynchronous suspension>

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-iotype-documentationA request to add or improve documentationtype-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions