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

  • SEARCH
  • Home
  • 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 7910773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:59:45+00:00 2026-06-03T12:59:45+00:00

I’m working on a modular component framework and have different needs for the code

  • 0

I’m working on a modular component framework and have different needs for the code in my test environment vs production. Each component has its own js file and these are being compiled together for production use, but left separate in my dev environment.

In production I want to trap errors in various stages of initialization so as to not break the call stack. In my development (uncompressed javascript), I do not want to trap the errors, so I can quickly get line numbers, etc to find where the breaks occur. Is there any way to use the closure compiler to manipulate a javascript file (such as removing a flagged line such as a comment opener and closer) that might allow me to do this?

For instance:

proto.instantiateChildFromDescriptor = function(childObj, callback, customDiv){
/*ProductionErrorTrap
    try{
/**/
    //code for instantiating a module
/*ProductionErrorTrap
    }catch(e){
        console.log("problem instantiating child in " + this.getName());
        console.error(e);
    }
/**/
}

replacing /*ProductionErrorTrap with /*ProductionErrorTrap*/ would work nicely (so is removing my stars on the second comment block, but they are there)

I can’t do this with a find and replace on the files themselves because it would mess with github. I suppose I could create a new copy of the files, run a find and replace on them and compile *those files, but It would be nice if I could do it all in the closure compiler.

Thanks

  • 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-03T12:59:47+00:00Added an answer on June 3, 2026 at 12:59 pm

    I think messing with compiled results, matching comments to emulate ifdefs is pretty unelegant.

    You could actually do something like this:

    debugTry(function() {
        alert('This is code that might cause an error');
    },function(e) {
        alert('Whoops! Caught error '+e);
    });
    

    Then while debugging you do:

    function debugTry(test,handle) {
        try {
            test();
        } catch(e) {
            handle(e);
        }
    }
    

    And in production:

    function debugTry(test,handle) {
        test();
    }
    

    Closure Compiler is pretty smart. With the first debugTry the example compiles to:

    try{alert("This is code that might cause an error")}
    catch(a){alert("Whoops! Caught error "+a)};
    

    With the second debugTry it compiles to:

    alert("This is code that might cause an error");
    

    As you see, the unnecessary code is detected and eliminated.

    Of course, things would be easier if you didn’t conditionally include a try block. If it’s just some statements included conditionally, not changing the structure of other code, you can do:

    /** @const */ var debug = false;
    
    if(debug) {
        alert('Yay for debugging!');
    }
    

    The alert will be compiled away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't

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.