Partilhar via


Why Handling of Exceptions is Critical in SharePoint Online(O365-S)

 

SharePoint Online imposes Resource Usage Limits on Sandbox solutions. Every user solution that is deployed on SharePoint online is subject to resource usage restrictions.

Each and Every resource used by the user solutions are monitored by SharePoint monitors. All user solutions in the site collection will be blocked automatically if the daily resource points exceeds the Usage Quota mentioned by the Site collection administrator for that site collection.

SharePoint Online administration center can be used to set the Resource usage Quota for every site collection from the total resources available.

 

image

Figure 1: SharePoint Online Administrator Center with Resource Usage Quota Option

 

image

Figure 2: Screen for setting the Usage Quota for site collection

 

Every site collection will have the Max Resource Points set and can be monitored by site collection administrators from the screen as shown in figure 3.

image

Figure 3: Site collection administrator view of resource usage for Current day and Average Usage for last 14 days.

 

These points are calculated based on Microsoft proprietary algorithm that takes into account the use of resources in the several resource categories by the sandboxed solutions that are installed in the site collection.

UnhandledExceptionCount is one of the resource categories that is measured and has a weightage of 50 Resources per point.

Unhandled Exception has an absolute limit of 3 which strictly means that if there are unhandled exceptions in the user solutions three within a day then all user solutions are blocked for that day.

If there are unhandled exceptions in an on-premise SharePoint solution, there is not much impact, except user will be shown an error message on the screen. However this is not the case with SharePoint Online solutions.

Developers and in turn site collection administrators cannot afford to have unhandled exceptions in the code.

A good approach is to handle every exception in the code and perform some logging. As SharePoint online doesn’t support logging to ULS or Windows Event logs or has access to file system logs, best way to do logging is to write to SharePoint list within the same site collection.

Note: Make sure the logger list and other resources exist before logging takes place, otherwise there are chances of unhandled exceptions within the catch block as well.

try

{

//User Solution Code

}catch(Exception ex)

{

//Perform logging to SharePoint List – Make sure List exists before logging begins.

}

Never throw an exception that is not handled by your code, no exceptions should get propagated to sandbox worker process.

Every developer should understand the criticality of unhandled exceptions and how user solutions are penalized in SharePoint Online environment.

Happy Sandboxed Coding!!