0

I'm writing a WIntRt application in C# and I use StreamSocket.

The fragment of code I have problem with looks like this

try
{
await StreamerConnection.socket.ConnectAsync(new Host("192.168.10.14", "8777");
}
catch(Exception ex)
{
ex.ToString();
}

My problem is that when remote host is inaccessible, my program instead entering the catch block, exists from function in which the try..catch block is. How can I handle situation when remote host is inaccessible and StreamSocket cannot connect to that host? How can I determine that it could not connect because destination host was unreachable?

xcoder37
  • 499
  • 6
  • 21
  • 1
    If the host is inaccessible, it certainly should enter the `catch` block. Are you **sure** that's not the behavior you're seeing? – Stephen Cleary Jun 12 '15 at 13:25
  • Definitely. In fact, I'm not sure what is happening to program control in case of hosts' incaccessibility, but it definietely doesn't enter the catch block or any code after the catch block, it exists the calling method or maybe even the calling thread..I guess it has something to do with asynchrony but I can't figure out what and how – xcoder37 Jun 12 '15 at 14:21
  • No, the control flow would be exactly the same as if you did a synchronous `try`/`catch`. – Stephen Cleary Jun 12 '15 at 15:12

0 Answers0