Handling Errors

If you have errors in your code (which we all know never happens), Python typically prints a message. If you enable the verbose option, Python provides more details about the error.

When running your script, you may want to handle errors when they happen. For example, you can print a message and stop the script execution. Refer to Exceptions for a list of Efinity® API-specific exceptions.

The API typically uses Python exceptions to indicate errors during function execution.

Below are two examples that handle errors.

Error Handling Case 1

def display_pin_names_with_exception(pin_names_list=[]):
    if len(pin_names_list) == 0:
        raise Exception("Pin name list is empty")
    else:
        for pin in pin_names:
            print("Pin name: " + pin)

# Calling function
try:
    display_pin_names_with_exception() # Will throw exception since pin name list is empty
except Exception as excp:
    print("Caught an exception: {}".format(excp))

Error Handling Case 2

# Get access to API exceptions
import api_service.excp.design_excp as DE

# Generate constraints and reports, handles error by catching exception
try:
    design.generate(enable_bitstream=False)
except DE.PTDsgCheckException as excp:
    print("Design check fails : {} Msg={}".format(excp.get_msg_level(), excp.get_msg()))
    sys.exit(1)
except DE.PTDsgGenConstException as excp:
    print("Fail to generate constraint : {} Msg={}".format(excp.get_msg_level(), excp.get_msg()))
    sys.exit(1)
except DE.PTDsgGenReportException as excp:
    print("Fail to generate report : {} Msg={}".format(excp.get_msg_level(), excp.get_msg()))
    sys.exit(1)