Handling exceptions from calculateToken