Export (0) Print
Expand All

AdControl Error Handling - Windows 8.0

Microsoft Advertising Services

Updated: August 2, 2013

Published: June 4, 2013

This topic provides basic information about how to handle errors that are generated by the AdControl.

Error Handling in Windows 8 Apps

JavaScript/HTML Apps

.NET Framework Apps

JavaScript/HTML Apps

To handle an AdControl error in a JavaScript app you:

  1. Set onErrorOccurred to the value of the error handling function.

  2. Code the error handling function.

onErrorOccurred is set in the data-win-options for the div of the AdControl. In the following example, the onErrorOccurred event is set to be handled by a function named errorLogger.

<div id="myAd" style="position: absolute; top: 53px; left: 0px; width: 250px; height: 250px; z-index: 1" 
     data-win-control="MicrosoftNSJS.Advertising.AdControl" 
     data-win-options="{applicationId: 'd25517cb-12d4-4699-8bdc-52040c712cab', adUnitId: 'ADPT33', onErrorOccurred: errorLogger}">
</div>

The error handling function is declarative and must be enclosed in the markSupportedForProcessing function.

The error handler catches the JavaScript error object when an AdControl error occurs. The error object provides two arguments to the error handler. For more information about this see the topic Special Error Properties from Asynchronous Windows Runtime Methods.

Below is an example an error handling function named errorLogger that handles the onErrorOccurred event.

WinJS.Utilities.markSupportedForProcessing(
window.errorLogger = function (sender, evt) {
    console.log(new Date()).toLocaleTimeString() + ": " + sender.element.id + " error: " + evt.errorMessage + " error code: " + evt.errorCode + \n");
});

See the topic JavaScript Error Handling Walkthrough for a walkthrough that demonstrates AdControl error handling in JavaScript.

.NET Framework Apps

Handling an AdControl error event follows the standard patterns and practices of the .NET framework. For an overview of event handling, see the topic How to: Raise and Consume Events.

To handle AdControl errors, you:

You set the ErrorOccurred event to the value of your error handler delegate using an assignment. Here is an example that uses the name “OnAdError” for the error handling delegate.

ErrorOccurred = OnAdError

Below is an example an error handling function named OnAdError that handles the ErrorOccurred event.

        private void OnAdError(object sender, AdErrorEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("AdControl error (" + ((AdControl)sender).Name + "): " + e.Error + " ErrorCode: " + e.ErrorCode.ToString());
        }

See the topic XAML/C# Error Handling Walkthrough for a walkthrough that demonstrates the use of the AdErrorEventArgs class and error handling in XAML and C#.

See the topic XAML/Visual Basic Error Handling Walkthrough for a walkthrough that demonstrates the use of the AdErrorEventArgs class and error handling in XAML and VB.

Support and Feedback

Get product support or report a bug in the advertising SDK by visiting the Windows 8 Dev Center support page (scroll down to the section "Microsoft Advertising support").

Send feedback about this documentation to adsfdbk@microsoft.com. There is no product support through this alias. Documentation feedback only.

Community Additions

ADD
Show:
© 2015 Microsoft