Errors
Important
Visual Studio App Center is scheduled for retirement on March 31, 2025. While you can continue to use Visual Studio App Center until it is fully retired, there are several recommended alternatives that you may consider migrating to.
App Center Errors allow you to handle the errors in your app and avoid potential issues in your app. This section examines how to catch and report the errors in your app. Learn more about best practices about when and how to use errors in the official documentation for exceptions.
Note
Handled Errors are currently only supported on the Xamarin platform.
General information
When running App Center in an application, the service reports all errors during the lifetime of the application. These errors are sent to the server when they occur (provided there's a network connection) or the next time the application is started.
Learn more about our feature set in our Errors documentation.
Integrate the Crashes SDK to get started
To track errors in your Xamarin app, integrate the Crashes module in the App Center SDK. Check out our Crashes SDK Documentation to learn how to do so.
Uncaught Errors (Crashes)
An uncaught error (crash) is an error that occurs outside of a try/catch block. App Center automatically reports these crashes by default, when integrating the crashes module of the App Center SDK.
Inside a Try/Catch Enclosure (Errors)
By calling TrackError
method inside try/catch enclosure, you can control what information is sent to the App Center service when an error occurs, and get a clearer picture of the error and the state of the device.
There are a number of benefits using the TrackError
method:
- Send reports to the service with greater accuracy.
- Send reports to the service with additional information.
Track Handled Errors in App Center
Include the Crashes SDK to handle errors and report them to App Center. As part of this module, you can track errors by using the TrackError
method:
try
{
int divByZero = 42 / int.Parse("0");
} catch (DivideByZeroException ex){
Crashes.TrackError(ex);
}
Learn more about how to use the Crashes SDK to track errors in Xamarin in our Crashes SDK Documentation.
Adding Additional Information to Error Catching
It's possible to tailor the error report sent to App Center to provide additional information for further context about the error. Achieve this by passing a Dictionary of strings key/value pairs to the TrackError
method. These properties are optional. For example:
try
{
using (var text = File.OpenText("saved_game001.txt"))
{
Console.WriteLine("{0}", text.ReadLine());
...
}
}
catch (FileNotFoundException ex)
{
Crashes.TrackError(ex, new Dictionary<string,string>{
{ "Filename", "saved_game001.txt" },
{ "Where", "Reload game" },
{ "Issue", "Index of available games is corrupted" }
});
}
Here the full exception (ex) is still being sent back to the App Center service, but in addition to this, a Dictionary containing additional debugging information is also being created and sent.
Limitations
- You can define a maximum of 20 properties per error, anything beyond that limit will be rejected.
- The maximum number of characters per error property key and error property value is 125 characters.