Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
MFS1102 Object Oriented Programming
•
•
•
•
•
•
•
•
<script type = "text/javascript"> <!–
window.print(; //-->
</script>
<script type = "text/javascript"> <!–
window.printme(); //-->
</script>
•
•
•
•
•
•
try{
var password = "123456";if ( password.length < 5 ){
throw "SHORT";} else if ( password.length > 10 ) {
throw "LONG";}
} catch ( err ) {if ( err == "SHORT" ){
alert ( "password must more than 5" );} else if ( err == "LONG" ) {
alert ( “password must less than 10" );}
}
Example
•
•
•
•
try { //Run some code here }
catch(err) { //Handle errors here
}
function message() { try{ showalert("Call showalert"); } catch(e) {
alert("error " + e); }
}
Example
•
•
•
•
•
Example
<html><head><script type = "text/javascript">
function myFunc() {var a = 50;alert("Value of variable a is : " + a );
}</script></head>
<body><p>Click the following to see the
result:</p><form>
<input type = "button" value ="Click Me" onclick = "myFunc();" />
</form></body>
</html>
Output
<script type = "text/javascript"><!-- function myFunc() {
var a = 100; var b = 0;try {
if ( b == 0 ) {throw( "Divide by zero error." );
} else {var c = a / b;
}}catch ( e ) {
alert("Error: " + e );}
} //--> </script>
<p>Click the following to see the result:</p><form>
<input type = "button" value = "Click Me" onclick ="myFunc();" /></form>
Output
•
•
•
EXAMPLE<head>
<script type = "text/javascript">
<!–-
window.onerror = function (msg, url, line) {
alert("Message : " + msg );
alert("url : " + url );
alert("Line number : " + line ); }
//-->
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me"
onclick = "myFunc();" />
</form>
</body>
•
<img src="myimage.gif"
onerror="alert('An error occurred loading the image.')" />