Register
Sign In
Skip over navigation
Home
Add New Question
Jobs
Products
Throw an exception in a constructor
Question posted
in
Computer Software
on
08 2010
Rate question difficulty level
0
0 Votes
hat happens if you throw an exception in a constructor???
Add an answer
Share
|
2 Answers
Guest
My response: I don't do things in a constructor that would cause an expection to be thrown. I use initialization and reset functions to do all of my allocates and deallocates and dangerous stuff. Defensive programming is necessary even in garbage colelction languages. It teaches valdiation before usage and error/exception handling. If you ever do small device work, you learn to valdiate everythign as you do not necessarily have virtual memory, or other resources at your disposal.
Problem is most folks who I've run into (+60%) who do C++ do not know anything abotu security programming, do not validate any potential exception calls, do not validate input to their itnerfaces, do not understand have to track allocated memroy and check for buffer overflow issues, etc. C++ is an exceptional language especialyl for cross platform work (which I do a lot of). You just need to know how to use your tools. Same with .NET, or any other tools/frameworks/etc that folks use.
08/12/2010
Mike Sigsworth
This is one of those topics that people have wildly varying opinions on. I don't like the idea of having Initialize methods. It makes it too easy to create a partially initialized object. But throwing exceptions in your constructor means you have to wrap your new()'s in a try/catch block all the time, which is ugly. So there really isn't one perfect answer to this question.
You should probably do your best to refrain from performing risky operations in a constructor that might cause exceptions, but what if your constructor takes a parameter and that parameter is invalid (i.e. null, empty, out of range, etc.)?
I believe that a constructor's purpose is to completely initialize an object. If it fails to do that, and there's no way to handle it, then an exception is what's needed.
11/06/2010
Add an answer*
Your name
Email
Enter the code shown above:
please wait..
Location:
United States
Tags:
object oriented
,
c++
,
c#
,
.net
Occupations:
Software\Web Development
add a question
Now hiring!
IT & Engineering Professionals w/ Poly
SRA International
Herndon, VA
Business focuses on providing high-end information technology solutions and support to clients within the ... Architects ? Configuration Management Specialists ? Software Engineers ? Software Developers ? Geospatial...
---------------------------
IT Application Analyst
Saint Barnabas Health Care System
Oceanport, NJ
projects. Participate in and provide leadership for development and support of automation initiatives. Research ... skills. Experience in w orking with and developing hospital information systems. Patient Accounting and/or registration...
---------------------------
Lead IT Developer-H/R Payroll, Staffing, and Learning
Home Depot
Atlanta, GA
to anticipate hardware and software design needs. The Lead Developer must have the ability to view packages and ... AND SCOPE - * Typically reports to Manager, Information Technology * No associates report to this role on a...
---------------------------
IT Mgr Software Engineering
Apollo Group
Phoenix, AZ
supervision and the software development guidelines and technology standards defined by Apollo Corporate IT, this ... Experience supervising and/or leading other professional level IT staff is required...
---------------------------
Senior Software Developer - Info Technology Job
Mercer
Deerfield, IL
Senior Software Developer - Info Technology-DEE000C5 Description Mercer is the global leader for trusted Human Resources ... information, please visit us at: www.mmc.com/diversity. Job Information Technology/Software Development Primary Location...
---------------------------
Software Development Manager 2 - Health IT
Northrop Grumman
Providence, RI
Northrop Grumman is seeking an experienced Software Development Manager to join our team of qualified, diverse ... years of relevant experience - Experience with IT Project Development Lifecycle - Strong Medicaid/Medicare business...
---------------------------
IT Mgr Software Development
Apollo Group
Phoenix, AZ
supervision and the software development guidelines and technology standards defined by Apollo Corporate IT, this ... design, development, coding, testing and debugging of new software or significant enhancements to existing software.
---------------------------
Software Development Analyst 2 - Health IT
Northrop Grumman
Providence, RI
Northrop Grumman Information Systems Sector is seeking a Software Development Analyst 2 to join our team of qualified, ... development life cycle (SDLC) in support of application software from design, development, testing, documentation...
Jobs
by
Simply
Hired
View all jobs