There are a very small number of exception types defined by WinRT, and a limited number of HRESULT that will be specifically designed for C #.
In general, the WinRT API design pattern avoids exceptions for everything except things that are programming errors and should be opened at design time (invalid arguments, missing features, etc.) or things that you really cannot recover from ( such as out of memory). You should avoid handling these types of exceptions with try \ catch , because they represent errors in your application or the inability of the system to continue running your application.
Instead, WinRT prefers the methods to succeed, but return objects with a status in them (for example, ResponseCode ), which you can request to see if this method succeeds.
The reason for this is that many developers cannot handle exceptions (due to the fact that they do not fully test their application in different configurations). An unhandled exception is guaranteed to reduce the process, which is not a great experience for clients, but the return value indicating failure can often be processed by applications either because they already check the status for other reasons (for example, you probably always want to check the status of HTTP, there is whether you have an error or not) or because the code is already resistant to "empty" results (for example, foreach is clearly defined on empty lists).
Not all APIs follow this pattern - especially those that were developed early on in Windows 8, but this is the pattern that you should see in most WinRT APIs. You will also notice many try style WinRT APIs that try to do something and return true or false , rather than throw an exception. Therefore, for the most part, your code should be free of try / catch blocks around WinRT API calls, although you still have to use them for your own code or third-party libraries.
source share