台南好想工作室-想知道講座-Promise error handling
- 4. 範例1範例1newnew PromisePromise((((resolveresolve,, rejectreject)) =>=> {{
consoleconsole..loglog(('Initial''Initial'));;
rejectreject(('errorerrorerror''errorerrorerror'));;
}}))
..thenthen(((()) =>=> {{
consoleconsole..loglog(('Do this''Do this'));;
}}))
..catchcatch((((errerr)) =>=> {{
consoleconsole..loglog(('Do not do that ''Do not do that '++ errerr));;
}}))
44
- 9. functionfunction errorExampleerrorExample(()) {{
resultresult == newnew PromisePromise((((resres,, rejrej)) =>=> {{
fsfsdfsdfdsffdsfddfdfsdfsdfdsfsdffsfsdfsdfdsffdsfddfdfsdfsdfdsfsdf //我是錯誤//我是錯誤
}}))..catchcatch((((errorerror)) =>=> {{
returnreturn "errorerrorerror""errorerrorerror"
}}))
returnreturn resultresult;;
}}
errorExampleerrorExample(())
..thenthen((((successsuccess)) =>=> {{
consoleconsole..loglog(('Do this ''Do this ' ++ successsuccess));;
}})) //Do this handle by inner function//Do this handle by inner function
..catchcatch((((errerr)) =>=> {{
consoleconsole..loglog(('Do not do that''Do not do that' ++ errerr));;
}}))
99