Error handling in JavaScript
Upcoming SlideShare
Loading in...5
×
 

Error handling in JavaScript

on

  • 1,275 views

My Talk at

My Talk at

Statistics

Views

Total Views
1,275
Slideshare-icon Views on SlideShare
1,237
Embed Views
38

Actions

Likes
0
Downloads
23
Comments
0

2 Embeds 38

https://twitter.com 37
http://eventifier.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Error handling in JavaScript Error handling in JavaScript Presentation Transcript

    • Handle with care Fehlerbehandlung in JavaScript Friday 8 November 13
    • WER BIN ICH? • Sebastian Springer • https://github.com/sspringer82 • @basti_springer Friday 8 November 13
    • Friday 8 November 13
    • Was ist ein Fehler? ☠ Friday 8 November 13
    • Was ist ein Fehler? ☠ Whoops, this should not happen. Friday 8 November 13
    • Fehlertypen Friday 8 November 13
    • Fehlertypen Friday 8 November 13
    • Fehlertypen Friday 8 November 13
    • Fehlertypen Friday 8 November 13
    • Fehlertypen Friday 8 November 13
    • Fehlertypen Friday 8 November 13
    • Eigene Fehler throw new Error('An error occurred'); Friday 8 November 13
    • Eigene Fehler var MyErr = function (message) { this.message = message; this.name = 'MyErr'; } MyErr.prototype = new Error(); MyErr.prototype.constructor = MyErr; Friday 8 November 13
    • Friday 8 November 13
    • Abfangen von Fehlern try { throw new Error('Hello World'); } catch (e) { console.log(e); } finally { console.log('Finished'); } Friday 8 November 13
    • Abfangen von Fehlern try { } catch (RangeError e) { } Friday 8 November 13
    • Abfangen von Fehlern try { } catch (RangeError e) { } Friday 8 November 13
    • Abfangen von Fehlern try { } catch (e) { if (e instanceof RangeError) { } } Friday 8 November 13
    • Callbacks Friday 8 November 13
    • Fehler in Callbacks Applikation Friday 8 November 13 Asynchrone Ausführung
    • Fehler in Callbacks Applikation Friday 8 November 13 Asynchrone Ausführung
    • Fehler in Callbacks Asynchrone Ausführung Applikation Operation Friday 8 November 13
    • Fehler in Callbacks Asynchrone Ausführung Applikation Operation Friday 8 November 13
    • Fehler in Callbacks Asynchrone Ausführung Applikation Operation ☠☂ ☏☣☢ Friday 8 November 13
    • Fehler in Callbacks Asynchrone Ausführung Applikation Operation Callback Friday 8 November 13 ☠☂ ☏☣☢
    • Fehler in Callbacks Asynchrone Ausführung Applikation Operation Callback Friday 8 November 13 ☠☂ ☏☣☢
    • Fehler in Callbacks function myTimeout() { throw new Error("whoops"); } Friday 8 November 13
    • Fehler in Callbacks function myTimeout() { throw new Error("whoops"); } try { setTimeout("myTimeout()", 0); } catch (e) { console.log(e); } Friday 8 November 13
    • Fehler in Callbacks ☠ function myTimeout() { throw new Error("whoops"); } try { setTimeout("myTimeout()", 0); } catch (e) { console.log(e); } Friday 8 November 13
    • Friday 8 November 13
    • Fehler in Callbacks $.ajax({ url: ‘/something’, success: function (data) { ... }, error: function (data) { ... } }); Friday 8 November 13
    • Friday 8 November 13
    • Fehler in Callbacks var fs = require('fs'); fs.readFile('file', function (err, d) { ... }); Friday 8 November 13
    • Fehler in Callbacks var fs = require('fs'); fs.readFile('file', function (err, d) { ... }); null Friday 8 November 13
    • Fehler in Callbacks Error { errno: ... code: ... path: ... message: ... } Friday 8 November 13
    • Events Friday 8 November 13
    • Error Events Subject Friday 8 November 13 Observer
    • Error Events Subject Friday 8 November 13 Observer
    • Error Events Subject Friday 8 November 13 Observer
    • Error Events Subject Observer on(‘error’, function... Friday 8 November 13
    • Error Events Subject Observer on(‘error’, function... ☠☂ ☏☣☢ Friday 8 November 13
    • Error Events Subject Observer on(‘error’, function... ☠☂ ☏☣☢ trigger(‘error’, {... Friday 8 November 13
    • Error Events Subject Observer on(‘error’, function... ☠☂ ☏☣☢ trigger(‘error’, {... Friday 8 November 13
    • Promises http://wiki.commonjs.org/wiki/Promises Friday 8 November 13
    • Promises In Javascript, promises are objects which represent the pending result of an asynchronous operation. (Martin Fowler) Friday 8 November 13
    • Promises $.ajax({ url: ‘/my/url’ }).done(function (data) { ... }).fail(function (data) { ... }).always(function (data) { ... }); Friday 8 November 13
    • Promises function promisedFunc() { var def = $.Deferred(); // do something asynchronous // success def.resolve(); // fail def.reject(); return def.promise(); } Friday 8 November 13
    • Promises promisedFunc().done(function () { // success }).fail(function () { // failure }).always(function () { // success & failure }); Friday 8 November 13
    • Promises $.when( promisedFunc(), promisedFunc() ).then(success, failure); Friday 8 November 13
    • Promises • http://api.jquery.com/category/deferred-object/ Client only • https://github.com/kriskowal/q Client + Server • https://github.com/kriszyp/node-promise Server only Friday 8 November 13
    • Node.js Domain Friday 8 November 13
    • Node domain var domain = require(‘domain’).create(); domain.on(‘error’, function (err) { console.log(err); }); domain.run(function () { ... }); Friday 8 November 13
    • Node Domain Wird ausgeführt bei: • • Friday 8 November 13 error-Events Exceptions
    • window.onerror Friday 8 November 13
    • window.onerror catch it all! Friday 8 November 13
    • window.onerror window.onerror = function (msg, url, nr) { ... return true; } Friday 8 November 13
    • window.onerror window.onerror Code Friday 8 November 13
    • und jetzt? Friday 8 November 13
    • und jetzt? Logging FTW! Friday 8 November 13
    • Logging Client Friday 8 November 13 Server
    • Logging Client Server ☠☂ ☏☣☢ Friday 8 November 13
    • Logging Log Message Client ☠☂ ☏☣☢ Friday 8 November 13 Server
    • Logging Log Message Client ☠☂ ☏☣☢ Friday 8 November 13 Server
    • Logging window.onerror = function (msg, url, nr) { $.ajax({ url: ‘/logger’ data: { msg: msg, url: url, nr: nr } }); return true; } Friday 8 November 13
    • Logging Fire and Forget Friday 8 November 13
    • Fragen? Friday 8 November 13
    • Sebastian Springer sebastian.springer@mayflower.de Mayflower GmbH Mannhardtstr. 6 80538 München Deutschland @basti_springer https://github.com/sspringer82 Friday 8 November 13