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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:04:53+00:00 2026-05-11T22:04:53+00:00

In Delphi, if there was an exception during construction of an object: any allocated

  • 0

In Delphi, if there was an exception during construction of an object: any allocated memory would be released and an exception would be thrown. For example, the following was guaranteed to either return a valid Camera object, or throw an exception:

Camera c = new Camera();

You never had to check the resulting variable for null:

Camera c = new Camera();
if (c == null)
   throw new Exception("Error constructing Camera") //waste of time

Is the same true in the CLR?

And are there other syntatical constucts where a return value is guaranteed to either be valid, or throw an exception?

  • Creating structures (e.g. Rectangle)?
  • getting a member of an enumeration?
  • the result of Object.ToString()?
  • mathmatical operations?

In the case of performing math:

Int32 aspect = 1650.0 / 1080.0;
if (aspect == null) 
   throw new Exception("Division of two numbers returned null")
  • 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-11T22:04:53+00:00Added an answer on May 11, 2026 at 10:04 pm

    A constructor in .Net is guaranteed to return a non-null instance of the type of the object. Whether or not the instance is valid depends on the individual semantics of the type.

    Exceptions thrown in a constructor will not be arbitrarily swallowed by the CLR (though user code can swallow them). The CLR will propagate an exception just like exceptions thrown in any other method and the objects will eventually be properly garbage collected.

    As for the other cases you mentioned

    • Creating structures: Structures by definition can’t ever be null. Exceptions thrown in the constructor will propagate normally
    • Getting a member of an enumeration: Enumerations are strutures / value types under the hood and also won’t ever be null
    • the result of Object.ToString(): This can (and sadly will) be null. String is a reference type and it’s perfectly legal to return null from a ToString override (please don’t).
    • Mathematical operations: This depends heavily on both the overflow setting of your project and the particular type being used (integral vs. floating point).

    The mathematical question almost deserves an answer on it’s own. On one hand the result of a mathematical operation on primitive types won’t ever be null. But it can still be invalid. For instance, the following code won’t throw but whether or not the result is valid depends highly on your specific scenario

    float f1 = 1.0;
    float f2 = f1 / 0;
    

    At this point f2 is a very specific float value that doesn’t represent a real number. Is it valid? Depends on your use case.

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

Sidebar

Related Questions

Are there any CI-Systems for Delphi like Hudson for Java? Does Hudson has any
Is there any equivalent of DocTest for Delphi. I use DUnit but I like
Is there any information available for the next version ( 2011 ) of Delphi
Is there a built-in Delphi function which would convert a string such as '3,232.00'
In Delphi XE UxTheme unit there is the following declaration function DrawThemeTextEx(hTheme: HTHEME; hdc:
Hi are there any nice videos on how to use exceptions in Delphi.
I need a Timer in a 'no form' Delphi unit (there's still a main
Are there examples which show how Delphi invokes the Active Directory Kerberos server to
Is there a way (on windows using Delphi 2010) to get the number of
Is there a Windows API call or Delphi call that will tell me what

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.