Title: How can I detect an error rather than have this Rust program abort?
Tags: rust;rust-0.8
Question: When running the following test program (below) using Rust 0.8 on win8, if I run two instances of the program simultaneously, when the first program is waiting for input (line 12), then the second program aborts (line 7) with fatal error message below.
To prevent the fatal error, I presume that I need to use the match statement, but I don't know enough yet about the type system and using match with it, but I have tried.
How can I get the program below to fail gracefully rather than abort, in this situation?
example test program :
001  use st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0cell75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ll;
002  use st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0rt75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0io75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0{Writer, Listener, Acceptor};
003  use st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0rt75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0io75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0net75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0tcp75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0TcpListener;
004  use st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0rt75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0io75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0net75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ip75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0{SocketAddr, Ipv4Addr};
006  fn main() {
007      let res_tcp_acceptor = TcpListener75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ind(SocketAddr { ip: Ipv4Addr(127, 0, 0, 1),
008                                                          port: 9876}).listen();
009
010      print("Connected OK. Start Listening? (y/n)  : ");
012      let s_input: ~str = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0io75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0stdin().read_line();
014      if s_input == ~"y" {
fatal error displayed by second instance of program:
task <unnamed&gt; failed at 'assertion failed: `(left == right) &amp;&amp; (right == left)`
(left: `0i32`, right: `-4092i32`)', C:\bot\slave\dist2-win\build\src\libstd\rt\
uv\net.rs:302


Here is another answer: That's a bug which should be reported.
The expected behaviour, as demonstrated by my Linux machine, is the raising of an IoError condition, which may be handled but which if unhandled will lead to task failure: task '<unnamed&gt;' failed at 'Unhandled condition: io_error: rt75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0io75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0IoError{kind: OtherIoError, desc: "address already in use", detail: None}', /home/chris/vc/rust/src/libstd/condition.rs:131.
Comment for this answer: You can file the bug report if you'd like—you've got all the information. The [Rust Condition and Error-handling Tutorial](http://static.rust-lang.org/doc/0.8/tutorial-conditions.html) (link is for 0.8, which I believe you are using) covers how such a thing *should* be able to be caught.
Comment for this answer: Ok, thanks. Will you log the bug? How should it be handled to prevent an error? I presume that only one instance can use the port. I presume that "match" should be used.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:11/01/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<rust><rust-0.8>', 'Title': 'How can I detect an error rather than have this Rust program abort?', 'ViewCount': 321, 'id': 19720763, 'user_AboutMe': '<p>I am quite proficient with Flutter.</p>\n', 'user_AccountId': 2206245.0, 'user_DisplayName': 'Brian Oh', 'user_Reputation': 8524.0, 'user_Views': 418.0, 'user_id': 1949390.0}}