I am trying out Dart and I've been struggling with this for quite a bit now. Calling:
runServer() {
HttpServer.bind(InternetAddress.ANY_IP_V4, 8080)
.then((server) {
server.listen((HttpRequest request) {
request.response.write('Hello, World!');
request.response.close();
});
});
}
Once works like a charm. And then, trying
try {
runServer();
} on Error catch (e) {
print("error");
} on Exception catch(f) {
print("exception");
}
Now I'd expect that if I were to use this try-catch and start listening to the same port more than once, because I'm catching ALL exceptions and ALL errors, the program wouldn't crash. However, after running the code twice, instead of entering any try/catch clause I get:
Uncaut Error: SocketException: Failed to create server socket (OS Error: Only one usage of each socket address (protocol/network address/port) is normally permitted.
While I understand what the error is, I don't understand why doesn't it simply enter the catch Error/Exception clause?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…