How can I find out which exceptions can be selected by a method?

I am writing code that calls the following method, which exists on Windows.Networking.PushNotifications

 // Summary: // Creates objects that you use to retrieve push notification channels from // the Windows Push Notification Services (WNS). These channels are bound to // an app or secondary tile. [Threading(ThreadingModel.MTA)] [Version(100794368)] public static class PushNotificationChannelManager { // Summary: // Creates an object, bound to the calling app, through which you retrieve a // push notification channel from Windows Push Notification Services (WNS). // // Returns: // The object, bound to the calling app, that is used to request a PushNotificationChannel // from the Windows Push Notification Services (WNS). [Overload("CreatePushNotificationChannelForApplicationAsync")] public static IAsyncOperation<PushNotificationChannel> CreatePushNotificationChannelForApplicationAsync(); } 

I want to be sure to cover all cases where exceptions can be thrown and deal with each accordingly. Is it possible to get a list of the different types of exceptions that can be thrown, and the different circumstances that can cause them?

I don't want to just have everything

 catch(Exception ex) { } 

This MSDN article states that "An exception occurs if you try to register a WNS push notification channel when there is no data connection." However, it does not indicate what type of exception or if there are other cases where an exception may be thrown.

How do I know if there are other types of exceptions?

+5
source share
3 answers

The only way is the documentation and the source code, although note that so many other exceptions can be OutOfMemoryException like OutOfMemoryException , TypeLoadException , ThreadAbortException and ... so the right approach, in my opinion, is to exclude you from something make calls stack with them and let other bubbles.

also read this Vexing exception

+4
source

If you can mimic one of the error conditions mentioned in this link, you should be able to use a common catch for an exception to see the type that was thrown.

I think he's going to throw a System.Runtime.InteropServices.COMException , though based on the error codes mentioned in the article though.

+1
source

I want to be sure to cover all cases where exceptions can be thrown and deal with each appropriately.

It is not possible to cover all cases where exceptions can be thrown and deal with each accordingly.

If you fully understand the circumstances in which a particular exception can be selected, and you understand the invariants of the program and know that they are either still valid or how to recover them, then you can recover from this exception.

But you may have, for example, an exception caused by a cosmic ray that distorts the state of the machine, which leads to an access violation. How are you going to recover from this? There is always a point where you fall where the program should raise its hands and support it.

+1
source

Source: https://habr.com/ru/post/1206171/


All Articles