Throw İfadesi

Throw ifadesi bir istisna oluşturmanıza olanak sağlar. Program akışını kontrol etmek ve doğru hata iletileri oluşturmak için Try ifadesi ile birlikte kullanılır.
Örnek;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<script type="text/javascript"> var x = prompt("Lütfen 5 ve 10 arasında bir sayı girin.", ""); try { if(x>10){ throw "hata1"; } else if(x<5) { throw "hata2"; } else if(isNaN(x)) { throw "hata3"; } else { document.location.href="http://www.meb.gov.tr/"; } } catch(hata) { if(hata == "hata1") { alert("Girdiğiniz sayı büyük."); document.location.href=""; } if(hata == "hata2"){ alert("Girdiğiniz sayı küçük"); document.location.href=""; } if(hata == "hata3"){ alert("Lütfen rakam giriniz."); document.location.href=""; } } </script> |
