I am using Angular and TypeScript.
I have used try catch construct for error handling in case of API call.
If any error occurs in try block it is simply NOT going to catch block.
App terminates there only.
I have tried using throw
as well.
Here is a sample code snippet,
try {
this.api.getAPI(Id).subscribe( // this.api is my api service and getAPI is present there
(data: any) => {
if (data == null) {
throw 'Empty response';
}
},
(error: HttpErrorResponse) => {
console.log(error);
};
} catch(e) {
console.log(e);
}
in some cases 'data' from API returns 'null',
but throw is not going to catch block
ALSO, tried without throw, it gives null error for 'data' ... in that case also not going to catch block.