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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:47:33+00:00 2026-05-22T12:47:33+00:00

Is OK to throw an exception when 0 is passed to allocate method? Thank

  • 0

Is OK to throw an exception when 0 is passed to allocate method?

Thank you.

P.S.

If n == 0, the return value is
unspecified.

Does it mean that allocate shouldn’t throw an exception? I am inclined to think that if throwing wasn’t allowed for n==0, then the standard would clearly spell it out.

  • 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-22T12:47:34+00:00Added an answer on May 22, 2026 at 12:47 pm

    All the standard has to say (§20.1.5/2) is that given

    • T – any type
    • X – an Allocator class for type T
    • a – a value of type X&
    • n – a value of type X::size_type,

    the return value of the expression a.allocate(n) is unspecified if n equals 0.

    One one hand, given that X::allocate doesn’t have any mandated exception specification and explicitly may throw std::bad_alloc, I don’t see why it couldn’t throw some other type of exception as well. On the other hand, the wording specifically calls out the condition wherein n equals zero and directly implies that there is a return value, meaning you shouldn’t throw. I think it may be open to some interpretation, but personally I’d side with the latter and consider it an unexceptional code-path.

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

Sidebar

Related Questions

Can I throw an exception on the SQL 2005 server so that I can
I am trying to throw an exception based on the exception type parameter passed
Three ways I see here: 1) make function return that value explicitly 2) add
How can I test whether a given method will throw an exception or not
In C# I want to communicate to the calling method that the parameters passed
Suppose you want to throw Exception like this: 'Project with the provided ID cannot
Why it's impossible to throw exception from __toString()? class a { public function __toString()
What is the best way to throw exception from the constructor initializer? For example:
If you throw an exception from inside an MFC dialog, the app hangs, even
We want to throw an exception, if a user calls DataContext.SubmitChanges() and the DataContext

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.