0

I am using typescript and used promises to maintain synchronous behavior in my code .As per my research though we have try catch bloc around promise we are getting un-handled exception when something goes wrong in our promise

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): false

to overcome this issue I have added catch bloc to my promise as below. However I am not confident about best practice of this usage. If anyone can share advice on this it would be very helpful.

async testMethod(pram1 : pramType): Promise<boolean>{
    try{
        return await this.promisemethod(pram1).catch(function () {
                                                tl.debug("Promise Rejected");
                                                return false;});

    }catch () {
        tl.debug("Method Failed");
    }   

}
Lalindu
  • 329
  • 3
  • 17
  • How comes it's AngularJS question? There's no mention of it. I guess it should have typescript and ecmascript-2017 tags instead. Please, provide http://stackoverflow.com/help/mcve that can replicate the issue, since it's unclear how you get this error. `.catch` is out of place here, but it should be handled with catch statement any way. – Estus Flask Feb 22 '18 at 13:43
  • 1
    You do not need both `.catch()` and `try`/`catch`. – str Feb 22 '18 at 16:54

0 Answers0