Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7759435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:37:41+00:00 2026-06-01T13:37:41+00:00

currently i have a module builder. in this condensed version of the script, a

  • 0

currently i have a module builder. in this condensed version of the script, a body click fires foo() which throws an error. i would like to attach an error handler to the whole module object to catch whatever is thrown from within it, not just during creation, but also in runtime. is it possible?

currently, “foo alert” comes up in the console. i would like to suppress that and let a central logger do the necessary log. in this case, i want to see “logged” instead.

$(function() {

    var moduleCollection = {};

    //creates modules, stores them and returns for reference
    function define(name, def) {
        var newModule = def();              //creates the module object
        moduleCollection[name] = newModule; //store

        //somewhere here, i must attach some sort of
        //error handlers for the module
        //something like:
        newModule.onerror = function(){
            //execute error procedure (like logging)
            console.log('logged');
        }

        return newModule //return as reference
    }

    //a module definition
    var mymod = define('mymod', function() {
        //foo chokes unintentionally and results into an error
        function foo() {throw new Error('foo alert');}

        function start() {
            //a body click calls foo
            $('body').on('click', function() {foo()});
        }
        return {start: start}
    });

    //start module
    mymod.start()

});​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:37:42+00:00Added an answer on June 1, 2026 at 1:37 pm

    If you want that, you’ll need to add try and catch at each level of code execution.

    That is, at “definition” time, in your constructors (if present), in each method body, and in each event handler.

    Also, perhaps it’s just your example code, but this:

    $('body').on('click', function() {foo()});
    

    Could simply be this:

    $('body').on('click',foo);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, in my settings module I have this: LOGIN_URL = '/login' If I ever
I currently have Zend setup to look for a layout script in each module's
I currently have a simple menu_alter hook in a new module I'm building which
I currently have a dropdownlist which is populated via an SQLDataSource from the Module
I currently have a script, which uses file globbing via the sys.argv variable like
Currently I have 1 Guice module in my project which defines all bindings. Now
I currently have an implementation using the pexpect python module, which interacts with Juniper,
I have a module ( Alien::GSL ) which I am working on. Currently it
I currently have 4 textboxes which will be used to store an ip address.
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.