23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

We already introduced Visual Studio’s Exceptions dialog in Chapter 2; refer back to Figure 2-16. For<br />

each type of JavaScript exception, this dialog supplies two checkboxes labeled Thrown and<br />

User-unhandled. Checking Thrown will display a dialog box in the debugger (Figure 3-5) whenever an<br />

exception is thrown, regardless of whether it’s handled and before reaching any of your error handlers.<br />

If you have error handlers, you can safely click the Continue button in the dialog, and you’ll eventually<br />

see the exception surface in those error handlers. (Otherwise the app will terminate.) If you click Break<br />

instead, you can find the exception details in the debugger’s Locals pane, as shown in Figure 3-6.<br />

FIGURE 3-5 Visual Studio’s exception dialog. As the dialog indicates, it’s safe to press Continue if you have an error<br />

handler in the app; otherwise the app will terminate. Note that the checkbox in this dialog is a shortcut to toggle the<br />

Thrown checkbox for this exception type in the Exceptions dialog.<br />

FIGURE 3-6 Information in Visual Studio’s Locals pane when you Break on an exception.<br />

The User-unhandled option (enabled for all exceptions by default) will display a similar dialog<br />

whenever an exception is thrown to the event loop, indicating that it wasn’t handled by an appprovided<br />

error function (“user” code from the system’s perspective).<br />

You typically turn on Thrown only for those exceptions you care about; turning them all on can make<br />

it very difficult to step through your app! Still, you can try it as a test, and then leave checks only for<br />

those exceptions you expect to catch. Do leave User-unhandled checked for everything else; in fact,<br />

unless you have a specific reason not to, make sure that User-unhandled is checked next to JavaScript<br />

Runtime Exceptions here because this will include those exceptions not otherwise listed. This way you<br />

can catch (and fix) any exceptions that might abruptly terminate the app, which is something your<br />

customers should never experience.<br />

98

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!