Details
-
Type:
Bug Detection
-
Status: Deprecated
-
Resolution: Unresolved
-
Labels:None
-
Message:Remove this "exception".
-
Highlighting:
-
Default Severity:Blocker
-
Impact:High
-
Likelihood:High
-
Covered Languages:C#, VB.Net
-
Remediation Function:Constant/Issue
-
Constant Cost:15min
-
Analysis Scope:Main Sources, Test Sources
Description
It may be a good idea to raise an exception in a constructor if you're unable to fully flesh the object in question, but not in an exception constructor. If you do, you'll interfere with the exception that was originally being thrown. Further, it is highly unlikely that an exception raised in the creation of an exception will be properly handled in the calling code, and the unexpected, unhandled exception will lead to program termination.
Noncompliant Code Example
class MyException: public std::exception { public: explicit MyException(const char* message): msg_(message) { //... if (bad_thing) { throw std::exception("A bad thing happened"); // Noncompliant } }
Attachments
1.
|
C# | RSPEC-4166 |
|
Active | Unassigned | |
2.
|
VB.NET | RSPEC-4893 |
|
Active | Unassigned |