Manual reporting

Most of our client libraries detect and report unhandled exceptions. But sometimes you have your own try/catch blocks. In those you need to manually report errors.

This guide aims to explain how.

The most basic way is simply to invke Err.Report():

try
{
    //some stuff that generates an exception
}
catch (Exception ex)
{
    Err.Report(ex);
}

You can also attach context information:

try
{
    //some stuff that generates an exception
}
catch (Exception ex)
{
    Err.Report(ex, yourContextData);
}

Using anonymous object

If you need to attach multiple values you can use an anonymous object:

try
{
    //some stuff that generates an exception
}
catch (Exception ex)
{
    Err.Report(ex, new { UserId = userId, UserState = state });
}

Result

Complex structures are supported.

Custom context collections

We also have an object overload which can transform any object into a context collection (one of the groups in the "Context Data" menu in the Coderr website).

Below we are using ToContextCollection() extension method which can transform any object (including complex objects) into a context collection.

try
{
    //some stuff that generates an exception
}
catch (Exception ex)
{
    var modelCollection = viewModel.ToContextCollection("ViewModel");
    var loggedInUser = User.ToContextCollection("User");
    Err.Report(ex, new[]{modelCollection, loggedInUser});
}

Result

Hence you can easily attach and group your information just as you like.

Creating custom context collections

You can also create custom context collections which will be automatically included with every error report.

Read more

Edit page at GitHub Create a documentation ticket Ask a question This page is generated using the open source project MarkdownWeb.