Advertisement
Guest User

try...throw...catch

a guest
Apr 23rd, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.74 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>try...throw...catch</title>
  5.     <script>
  6.         function myFunction(){
  7.             try{
  8.                 var x=document.getElementById('demo').value;
  9.                 if(x=="") throw "vacio";
  10.                 if(isNaN(x)) throw "no es numero";
  11.                 if(x>10) throw "es mayor";
  12.                 if(x<5) throw "es menor";
  13.                 var y=document.getElementById('mess');
  14.                 y.innerHTML="Correcto!";
  15.             }
  16.             catch(e){
  17.                 var y=document.getElementById('mess');
  18.                 y.innerHTML="Error: "+ e + ".";
  19.             }
  20.         }
  21.     </script>
  22. </head>
  23. <body>
  24.     <h1>Detectando errores y personalizando</h1>
  25.     <p>Porfavor introduce un numero entre 5 y 10:</p>
  26.     <input type="text" id="demo" />
  27.     <input type="button" onclick="myFunction();" value="Probar valor" />
  28.     <p id="mess"></p>
  29. </body>
  30. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement