All functions and properties should be called within a try-catch block. When an error occurs in a function, an exception will be thrown and caught by the catch block. You can retrieve the Data[“ErrorCode”] and Data[“ErrorMessage”] in the exception to determine the error. The NI-ATE Core C# library has a defined list of error codes in the class AteCoreStatusCode which you can compare to the value of the error code in the exception.

Catching Exceptions during Session Creation

using NationalInstruments.AteCore;
using NationalInstruments.AteCore.StatusCode;

IAteCoreSession ateCoreSession = null;
try
{
	ateCoreSession = await AteCoreSession.CreateAteCoreSessionAsync(hostname, password);
}
catch (Exception ex)
{
	if (ex.Data["ErrorCode"].Equals(AteCoreStatusCode.NIATECORE_ERR_INCORRECT_PASSWORD))
	{
		Console.WriteLine("Exception: {0}", ex.Data["ErrorMessage"]);
	}
}
finally
{
	if (ateCoreSession != null)
	{
		// To close the session.
		ateCoreSession.Dispose();
	}
}