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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:23:41+00:00 2026-05-16T00:23:41+00:00

I came across a design that overrides [Scriptable.put][1] in a subclass of ScriptableObject to

  • 0

I came across a design that overrides [Scriptable.put][1] in a subclass of ScriptableObject to do some conversion. If the conversion fails the code is throwing an exception. Which means that property assignments like following code can cause a runtime exception to be thrown

    aScriptable.dateOfArrival = aVar;

By default rhino wouldn’t let the script catch a runtime exception thrown during [Scriptable.put][1]. So catch block in following code will never run:

    try{    
      aScriptable.dateOfArrival = aVar;
    }catch(e){
    //will not run even if above assignment generates an exception. Script will be terminated instead
    }

Overriding ContextFactory.hasFeature() with following code makes the above catch block work:

    protected boolean hasFeature(Context cx, int featureIndex) {
      if(featureIndex == Context.FEATURE_ENHANCED_JAVA_ACCESS){
        return true;
      }
      return super.hasFeature(cx, featureIndex);
    }

My question is that whether the design decision to make property assignment throw exception is correct or property assignments are never supposed to throw exceptions?

[1]: http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/Scriptable.html#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object)

  • 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-16T00:23:42+00:00Added an answer on May 16, 2026 at 12:23 am

    IMO it doesn’t make sense to throw an exception by design from the put method that JS code can’t catch. I think throwing an exception on setting a property is fine, although not that common. Note that JS code can easily reconfigure a property (in ECMAScript 5) with a custom setter that throws.

    On the other hand, I think it would be quite surprising if a property getter throws an exception.

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

Sidebar

Related Questions

I came across some code recently that used a custom error handler to turn
I came across a controller in an older set of code (Rails 1.2.3) that
Some time ago I came across a website that described a binary-to-text encoding which
I came across a printed article by Bertrand Meyer where he states that tests
I came across this class while reading a C# book and have some questions.
I came across this snippet of code on MSDN: entityBuilder.Metadata = @res://*/AdventureWorksModel.csdl| res://*/AdventureWorksModel.ssdl| res://*/AdventureWorksModel.msl;
I came across a code snippet like this: Timestamp expiryDate = Timestamp.valueOf(dateStr + +
I'm pretty new to Design Patterns.I just came across Factory Design Pattern. I understood
I came across this piece of code on a website. main(i) { gets(&i); puts();
I came across this code in a large codebase DWORD WINAPI ThreadFunc (LPVOID lpParam)

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.