Added exception throwing and handling.