I was trying to use ServiceException which was not working. To fix this, I used a different Exception method: cathch (Microsoft.Kiota.Abstractions.ApiException ex).
This method works perfectly, and it removes the need for a general exception to catch this specific error.