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 7676419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:11:42+00:00 2026-05-31T17:11:42+00:00

i have this function in my code and I’m using throw to create meaningful

  • 0

i have this function in my code and I’m using throw to create meaningful errors (rather than failing silently). However, when i structure my function this way, if i call defineSandbox() with an error, it stops the whole script.

//defineSandbox is in an object, for now i name "myObj"

var defineSandbox = function (sandboxName,SandboxDefinition) {

    //validation
    if(!is.validString(sandboxName)) {
        throw statusMessages.sandbox.invalidName;
    }
    if(!is.validFunction (SandboxDefinition)) {
        throw statusMessages.sandbox.invalidDefinition;
    }

    //...some more validation here

    //...sandbox builder code if validation passes (code wasn't returned)

    registered.sandboxes[sandboxName] = newSandbox;
};

//intentional error, non-string name
myObj.defineSandbox(false);                        

//...and so the rest of the script from here down is not executed  

//i can't build this sandbox anymore
myObj.defineSandbox('mySandbox',function(){...});  

what i would like to have is if one call fails, it gives out an error but still tries to continue to run the script. how do i structure this code so that i can achieve that?

  • 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-05-31T17:11:44+00:00Added an answer on May 31, 2026 at 5:11 pm

    Typically, you don’t want to continue execution when you manually throw a new error. If you want to have it for a logging purpose, you should consider an self-created internal solution.

    However, to catch a thrown error you need to invoke a try / catch statement.

    try {
        myObj.defineSandbox(false); 
    } catch( ex ) {
        // execution continues here when an error was thrown. You can also inspect the `ex`ception object
    }
    

    By the way, you can also specify which kind of error you want to throw, for instance a type error or a reference error like

    throw new TypeError();
    throw new ReferenceError();
    throw new SyntaxError();
    etc.
    

    Complete list: MDN

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

Sidebar

Related Questions

I have this code: function submitTwice(f){ f.action = 'http://mydomain.com/threevideopage.php'; f.target='name'; f.submit(); } I left
I have this function in my Javascript Code that updates html fields with their
We have this anonymous function in our code, which is part of the jQuery's
i have this code $(function() { $('#ans_vote a span').click(function(){alert('working');return false;});}); and this html <div
I have this piece of code: function func1(text) { var pattern = /([\s\S]*?)(\<\?(?:attrib |if
I have this piece of code: var myObj = function () { this.complex =
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
I have this code: $(div[id^='intCell']).mouseover(function() { $(this).css({ border:,1px solid #ff097c}); }).mouseout(function() { $(this).css({border:,1px solid
I have just come across this code: function test(){ //... if ( $profilerule ==
I have this code in a function $_SESSION['id'] = $id; $_SESSION['pineapple'] = $hashbrown; $_SESSION['username']

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.