'What can I add to a catch statement to show the properties that caused an error?

I have a web service that uses this 3rd party call(geoLock.AdjustSensorsAsync) to create an object.

When it works, it works fine. Here it is:

geologicalEvent.LocationName = geologicalEvent.LocationName;
try
{
    sensorResult = await geoLock.AdjustSensorsAsync(
        geologicalEvent.LocationId,
        geologicalEvent.LocationName,
        geologicalEvent.LocationStart.ToUniversalTime(),
        geologicalEvent.LocationEnd.ToUniversalTime()
        );
} catch
{

}

But sometimes a bad LocationStart or LocationEnd is passed to it and I'll get an error like:

FaultException: "Unable to record. Invalid time."

Right now, it just shows the line number of the error, but I'd like to see more detailed info on what entity caused the error.

What can I add to the catch to show which specific LocationId and also the 'LocationStart' and 'LocationEnd' that caused it?

Thanks!



Solution 1:[1]

geologicalEvent.LocationName = geologicalEvent.LocationName;

try
{
    sensorResult = await geoLock.AdjustSensorsAsync(
    geologicalEvent.LocationId,
    geologicalEvent.LocationName,
    geologicalEvent.LocationStart.ToUniversalTime(),
    geologicalEvent.LocationEnd.ToUniversalTime()
    );
}
catch (Exception e)
{
    Console.WriteLine("{0} Exception caught.", e);
}

Something like that maybe? Using the 'catch (Exception e)' to do a console writeline and see what it spits out.

Reference: Microsoft documentation - try-catch

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Svyatoslav Danyliv