How about situations, when I haven't Exception (it's not try/catch), but I still need to send a custom error message to the toast? When I try to use throw new AuraHandledException('My custom msg here'); I get FATAL_ERROR System.AuraHandledException: Script-thrown exception in this case.

  • Can you post your code? – kurunve Mar 12 at 16:16
  • You already asked this , hows this different ? – Pranay Jaiswal Mar 12 at 16:16
  • No. It was about exception's error. – Yagami Raito Mar 12 at 16:36

For reasons I don't understand, you have to invoke the setMessage method to output a custom message on the client-side:

    String m = 'My cusom msg here';
    AuraHandledException e = new AuraHandledException(m);
    throw e;
  • I can still make following lines working (even as part of managed package): } catch(Exception ex) { throw new AuraHandledException(ex.getMessage()); } – kurunve Mar 12 at 16:17
  • It still looks like state == "SUCCESS" and green toast. But in System.debug('Some error msg') all is ok: I can see this error in debug. – Yagami Raito Mar 12 at 16:35

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.