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?– kurunveMar 12, 2019 at 16:16
-
You already asked this , hows this different ?– Pranay JaiswalMar 12, 2019 at 16:16
-
No. It was about exception's error.– Yagami RaitoMar 12, 2019 at 16:36
1 Answer
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;
-
2I can still make following lines working (even as part of managed package):
} catch(Exception ex) { throw new AuraHandledException(ex.getMessage()); }
– kurunveMar 12, 2019 at 16:17 -
It still looks like
state == "SUCCESS"
and green toast. But inSystem.debug('Some error msg')
all is ok: I can see this error in debug. Mar 12, 2019 at 16:35