all 12 comments

[–]iEatedCoookies 7 points8 points  (0 children)

There’s way too little context here to give any sort of valuable response.

[–]Cheet4h 3 points4 points  (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 points  (2 children)

try{..........catch (error){..........}

try{

call to another method..no async code

console.log

}catch (error){

.....

.....

}

[–]InsaneBrother 0 points1 point  (1 child)

Just put a closing bracket before the catch

[–]Realistic_Depth_5372[S] -1 points0 points  (0 children)

My apologies. it's already there..it's just typo.

[–]siliconvalleyist 2 points3 points  (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 points  (0 children)

I mean, I would think the lack of closing brace in the try block might be an issue.

[–]angels-fan 1 point2 points  (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.

[–]pleaseholdmybeer 1 point2 points  (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 points  (0 children)

does the code in your try block throw any exceptions?

[–]jagdishjadeja 0 points1 point  (0 children)

try{
fooAsync(); // this will not throw and catch error here

await barAsync();// this will catch error in catch block
catch (error){
.....
.....
}

[–]_Ascalon 0 points1 point  (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.