I am trying to understand why the error message (page is empty) in my code and not displayed it Call it with the following statement:
add document.write ((10, wrong_input));
program.js <{P>
var add = function (a, b) {if (typeof a! == 'number 'Typeof b! ==' number ') {Throwing {name:' TypeError 'Message:' Add number of needs'} (e) {document.writeln (e.name + ':' + e.message) ; }} Return A + b; }program.html
& lt; Html & gt; & Lt; Body & gt; & Lt; Pre & gt; & Lt; Script src = "program.js" & gt; & Lt; / Script & gt; & Lt; / Pre & gt; & Lt; Div & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;
throw statementhold section, tryyou should throw and hold separately. For example:var add = function (a, b) {if (typeof a! == 'number' || typeof b! == 'number') {throw {name: TypeError ', Message:' Add required numbers'}} Come back; } Try {add ('foo', 1); } Grip (Pre) {Warning (ex.message); }Note that I replaced the
document.writeln with thewarning , because the former will overwrite the whole document if this page Runs after load. If you want to look something better, then directly manipulate the dome (by changing the internal HTML of some element, adding a node etc).
No comments:
Post a Comment