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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:03:23+00:00 2026-05-25T16:03:23+00:00

I have a function, downloadAsync() , that returns a CommonJS promise (using Q ).

  • 0

I have a function, downloadAsync(), that returns a CommonJS promise (using Q). It can fail in two ways:

  1. The file can already be downloaded, in which case we know immediately.
  2. The download process could fail, in which case we know some time later.

In case (1), since I know before anything asynchronous happens, I could throw an exception. In case (2), I’d have to reject the promise.

My question is, should my API be uniform and always signal error by rejecting the promise? Or should I throw exceptions for immediately-determinable invalid state conditions? As another example, if the user passed me an invalid argument, it would seem much more sensible to throw an error than to reject the promise.

Some clarity on how “exceptional” promise rejection really is would be great, as well; does usage there map one-to-one with exception usage practices, or do we use it for non-exceptional failure as well?

  • 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-25T16:03:24+00:00Added an answer on May 25, 2026 at 4:03 pm

    If you want to know what you should do when your function (which implements Q) should do when presented invalid input that could be detected synchronously, I looked at the source code for Q, to see what Q did.

    Here’s an example.

    if (fallback === undefined) {
        fallback = function (op) {
            return reject("Promise does not support operation: " + op);
        };
    }
    

    When Q is presented with invalid input, Q invokes the resolver with a rejection object. Therefore you could be justified in having your API behave similarly, rather than trying to modify the behavior of the underlying library.

    Plus, look at it from a standpoint of anyone who consumes your API. Do they want to develop and maintain two exception handling code paths, or one?

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

Sidebar

Related Questions

In my Java code I have function that gets file from the client in
i want to have function like delete file from database by using link instead
Hii, I have function established in child page, that is using in the childpages.
I have function that returns the index of a character GetCharFromPos(Pt: TPoint): Integer; now
I have a function that exports a table into a CSV file, then I
I have function getCartItems in cart.js and I want to call that function in
So I have function that formats a date to coerce to given enum DateType{CURRENT,
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function that gets x(a value) and xs(a list) and removes all
I created a class: class A: aList = [] now I have function that

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.