However, since `console.log` is only available in Firefox (Or on a page that includes Firebug Lite), your code would be more portable if you used a traditional approach + a little jQuery (This example uses jQuery 1.4.1):
- function myFunctionThatMightHaveAnError(){
- // instead of just failing silently, actually throw an error
- $.error("My special error");
- }
- // Then use a try/catch block to handle it
- try {
- myFunctionThatMightHaveAnError();
- alert("No error!"); // this line would only run if no error were thrown
- } catch (e) {
- if(e == "My special error") {
- // Handle error
- }
- }