4AspNet IPInfo v1.0

IPInfo.ThrowIfNotFound Property

Gets or sets value indicating whether to throw an exception when country information cannot be found.

public bool ThrowIfNotFound {get; set;}

Property Value

true if exception must to be thrown when information is absent; otherwise false. The default is false.

Example

The following example demonstrates using of ThrowIfNotFound property.

public void CheckCountryNames()
{
    // assume what license is already initialized

    // initializing a new instance of IPInfo
    IPInfo ipi = new IPInfo();

    CountryInfo ci = ipi.GetInfoByCountryCode("US");
    string countryName = ci.CountryName;    // countryName equals to "United States"

    ci = ipi.GetInfoByCountryCode("XXX");    // not existed code is used; information is absent
    countryName = ci.CountryName;            // countryName equals to "N/A"

    ipi.ThrowIfNotFound = true;

    ci = ipi.GetInfoByCountryCode("XXX");    // exception of type CountryInfoNotFoundException is thrown !
}

See Also

IPInfo Class | ForAspNet.IPInfo Namespace