10

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.

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

1 Answer 1

20

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);
    e.setMessage(m);
    throw e;
2
  • 2
    I can still make following lines working (even as part of managed package): } catch(Exception ex) { throw new AuraHandledException(ex.getMessage()); }
    – kurunve
    Mar 12, 2019 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. Mar 12, 2019 at 16:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .