locked
[c++/cx] StreamSocket Wrong ip or port or connection error

    Question

  • Hi.

    I open socket and it's work. But if i input wrong ip or port i take error 

    First-chance exception at 0x74964B32 in App4.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x0543C7A8. HRESULT:0x8007274D
    
    If there is a handler for this exception, the program may be safely continued.

    how catch exeption wrong ip/port/coonection.

    		HostName^ hostName;
    		try
    		{
    			hostName = ref new HostName("localhost");
    		}
    		catch (InvalidArgumentException^ e)
    		{
    			return false;
    		}
    		StreamSocket^ socket = ref new StreamSocket();
    
    		CoreApplication::Properties->Insert("clientSocket", socket);
    
    
    		volatile bool asyncOperationCompleted = false;
    		task<void>(socket->ConnectAsync(hostName, "22113", SocketProtectionLevel::PlainSocket)).then([&asyncOperationCompleted] (task<void> previousTask) { 
    			try{
    				previousTask.get(); 
    				asyncOperationCompleted = true;
    			} 
    			catch( ... ) { 
    				asyncOperationCompleted = true;
    			}
    		});
    
    
    		while( false == asyncOperationCompleted ) 
    		{
    			CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneIfPresent);
    		}

    in StreamSocket sample c++ this error....

    First-chance exception at 0x74964B32 in StreamSocket.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x008FD9AC. HRESULT:0x8007274D


    Tuesday, March 26, 2013 11:54 AM

Answers

  • Check whether your exception is caught or not actually.

    catch( Exception^ ex ) { 				
            OutputDebugStringW(L"\n### Connection Failed\n");
            OutputDebugStringW(ex->Message->Data());
    			}

    Remember that, Platform::Exception can not handle null.

    Exceptions (C++/CX)

    Platform::Exception Class


    If exception is caught originally, you can  disable following option when a pop-up window is thrown in Visual Stdio.

    Break when this exception type is thrown

    Now execution will not terminated and execute your code inside the catch block.


    • Marked as answer by Mikhail Bfox Tuesday, March 26, 2013 3:00 PM
    Tuesday, March 26, 2013 2:54 PM