I am creating a button that will allow System Admins to reset user passwords via System.resetPassword. We have password restrictions setup such that a password must exist for 24 hours. Therefore, if the button is clicked twice in the same day, an "UNKNOWN_EXCEPTION: Your password cannot be reset at this time. Please contact your organization's administrator for more information." is thrown to the page.

I was hoping to be able to catch this error, however even when I put a try catch around it, the error still comes up on the page. Is there a special way to catch this exception?

for (User u : users) {
    try {
        System.resetPassword(u.Id, true);
    catch (Exception e) {
        usersUnableToReset += u.Username;
    usersAbleToReset += u.Username;

No, UnexpectedException, AssertException, and LimitException are all uncatchable.

Easy enough to verify via Execute Anonymous:

    throw new UnexpectedException();
catch(UnexpectedException e) { }
| improve this answer | |
  • Thanks for the answer, that's what it appeared to me from my tests. Do you have any background as to why those are uncatchable? – Developer Guy Dec 12 '19 at 21:59
  • Well, for the LimitExceptionif it was catchable, then it wouldn't really work as a limit... For AssertException I think it's supposed to break stuff if the assertion is not true. – Caspar Harmer Dec 13 '19 at 0:05
  • Those cases make sense to me, but the password reset UnknownException doesn't really. I want to try to reset the User's password, if I get an exception due to it already changing in the last 24 hours, I simply want to catch it, log the user, and then continue trying to reset the rest of the users. – Developer Guy Dec 13 '19 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.