Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7188

Why does my if condition not prevent my script from crashing?

$
0
0

I have a script which I launch using terminal and it always works well but sometimes randomly it throws following error:

TypeError: Cannot read property 'Name' of undefined

This script goes through same lines of code thouthands of times before it crashes because of this error. Here's the problematic line:

setTimeout(function() {deleteAlert(data[This].Name, intent); }, 2000);

How do I prevent my program from crashing? I tried doing this:

  if (data[This] && data[This].Name) {    setTimeout(function() {deleteAlert(data[This].Name, intent); }, 2000);  } else {    console.log(colors.red('ATTENTION: ') +"alert not deleted");  }

But it still sometimes throws an error at the same line. I mean it passes through data[This] && data[This].Name succesfully and then hits an error. How do I change this condition so that this error will not crash my script?


Viewing all articles
Browse latest Browse all 7188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>