assert - JavaScript contracts and assertions -


this has bugged me while. throw exception on assertion failure, helpful if can catch exception (in case alert user). if can't catch exception, then

  1. i'm relying on browser notify user there's been internal error (the browser may nothing, user never finds out there's problem), and
  2. i don't look-in, , can't clean up.

so, there way handle assertion errors in javascript? there way catch uncaught exceptions? note i'm not interested in unit testing, user errors, , on - i'm concerned contract programming, both user , developer need know there has been error.

for assertions, there console.assert(). log message , go on.

with html5 possible catch unhandled exceptions using window.onerror handler. there's excellent article on dev.opera how can used show fancy error messages user , log exceptions server.

if can't use that, you're left wrapping try-catch-clauses around (especially "execution entry points" event handlers, timeouts , co.). or handle errors before throwing them:

function smarterror(message) {     error.call(this, message);     $('<div class="error">some problem occured, app stop working</div>')         .appendto("body");     $.post("/log/clientside/js.php", this);     ... }  if (something.does(! "work"))     throw new smarterror("mysterious problem"); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -