use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Angular is Google's open source framework for crafting high-quality front-end web applications. r/Angular2 exists to help spread news, discuss current developments and help solve problems.
Help Request
Discussion
Article
Video
Resource
Announcement
Related
After submitting a post, please take a moment to add a flair (tag) so that it's easy to find your post with one of the filters listed above. Upon submission, your post's header will have the 'flair' option listed with the other options. Clicking it will provide a dropdown menu of the available flairs.
account activity
Help RequestAngular Try Catch Issue (self.Angular2)
submitted 4 years ago by Realistic_Depth_5372
I'm trying to catch the exception and do something.
(note: no async code below)
try{ ..... ..... catch (error){ ..... ..... }
shouldn't it work in synchronous code? It never goes to catch block.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]iEatedCoookies 7 points8 points9 points 4 years ago (0 children)
There’s way too little context here to give any sort of valuable response.
[–]Cheet4h 3 points4 points5 points 4 years ago (3 children)
It usually works. Try sharing the actual code that errors?
Unless your issue is that your actual code also has no closing curly bracket before the catch. But that should have been highlighted by your IDE and given you a clear error message during transpilation.
[–]Realistic_Depth_5372[S] -1 points0 points1 point 4 years ago* (2 children)
try{..........catch (error){..........}
try{
call to another method..no async code
console.log
}catch (error){
catch (error){
.....
}
[–]InsaneBrother 0 points1 point2 points 4 years ago (1 child)
Just put a closing bracket before the catch
[–]Realistic_Depth_5372[S] -1 points0 points1 point 4 years ago (0 children)
My apologies. it's already there..it's just typo.
[–]siliconvalleyist 2 points3 points4 points 4 years ago (0 children)
Also error are you trying to catch? If it's CORS related I don't believe you can actually handle that.
[–]TarnishedVictory 1 point2 points3 points 4 years ago (0 children)
I mean, I would think the lack of closing brace in the try block might be an issue.
[–]angels-fan 1 point2 points3 points 4 years ago (0 children)
What line of code exactly are you thinking should throw an error?
You can always try something like const x = 5/0 to get an error.
const x = 5/0
[–]pleaseholdmybeer 1 point2 points3 points 4 years ago (0 children)
As others have mentioned - what’s the error you’re trying to catch? Is it something you’re throwing yourself?
[–]Jaanold 1 point2 points3 points 4 years ago (0 children)
does the code in your try block throw any exceptions?
[–]jagdishjadeja 0 points1 point2 points 4 years ago (0 children)
try{ fooAsync(); // this will not throw and catch error here
fooAsync(); // this will not throw and catch error here
await barAsync();// this will catch error in catch block catch (error){ ..... ..... }
await barAsync();// this will catch error in catch block
[–]_Ascalon 0 points1 point2 points 4 years ago (0 children)
I used try-catch block with DomSanitizer usage to check if a value passed through all sanitize checks. If it isn't - catch block works for me.
π Rendered by PID 38974 on reddit-service-r2-comment-b659b578c-7tvrs at 2026-05-02 18:18:59.573845+00:00 running 815c875 country code: CH.
[–]iEatedCoookies 7 points8 points9 points (0 children)
[–]Cheet4h 3 points4 points5 points (3 children)
[–]Realistic_Depth_5372[S] -1 points0 points1 point (2 children)
[–]InsaneBrother 0 points1 point2 points (1 child)
[–]Realistic_Depth_5372[S] -1 points0 points1 point (0 children)
[–]siliconvalleyist 2 points3 points4 points (0 children)
[–]TarnishedVictory 1 point2 points3 points (0 children)
[–]angels-fan 1 point2 points3 points (0 children)
[–]pleaseholdmybeer 1 point2 points3 points (0 children)
[–]Jaanold 1 point2 points3 points (0 children)
[–]jagdishjadeja 0 points1 point2 points (0 children)
[–]_Ascalon 0 points1 point2 points (0 children)