markmnl
markmnl

Reputation: 11426

How to know what type of exceptions Windows store app types could throw?

I am using this method: DatagramSocket.BindEndpointAsync()

How the frig am I to know what type exceptions it could throw?? This offical sample shows catching all exceptions like so:

        // Start listen operation. 
        try 
        { 
            await listener.BindServiceNameAsync(ServiceNameForListener.Text); 
            rootPage.NotifyUser("Listening", NotifyType.StatusMessage); 
        } 
        catch (Exception exception) 
        { 
            CoreApplication.Properties.Remove("listener"); 

            // If this is an unknown status it means that the error is fatal and retry will likely fail. 
            if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown) 
            { 
                throw; 
            } 

            rootPage.NotifyUser("Start listening failed with error: " + exception.Message, NotifyType.ErrorMessage); 
        } 

But that seems terribly sloppy - surely there is a better way?

Upvotes: 2

Views: 344

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125610

C# does not require developer to mark each method with a list of exceptions that it can throw (Java has that requirement). That's why you have to rely on documentation or examine source code and figure it out.

Async/Await does not change anything in that case.

Upvotes: 1

Related Questions