Problem 1843

Summary: Failure of G4UnitDefinition::GetValueOf() should be a "hard error", not a warning
Product: Geant4 Reporter: gahs
Component: global/managementAssignee: Gabriele Cosmo <Gabriele.Cosmo>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P5    
Version: 10.2   
Hardware: All   
OS: All   

Description gahs 2016-03-11 19:36:45 CET
When G4UnitDefinition::GetValueOf(const G4String& str) is asked for the value of a unit that does not exist, it prints a non-fatal warning and returns 0.  This is pretty much guaranteed to give wrong simulation results, so it really should be a fatal exception, or some other hard, simulation-stopping exception.

The only reason I can think of for not making it fatal is that there is currently no other simple way to query whether a unit exists in the table.  This could be easily remedied.

Note bugs #1535 and #1842 are similar but a little different, since those bug reports both request that a check for invalid units be added. (E.g., "km" for an energy.)  Here the request is for a general hard failure in the case of completely unrecognized units, since multiplying by 0 is never a desirable unit conversion.
Comment 1 Gabriele Cosmo 2016-03-16 21:33:59 CET
I agree with the suggestion. I submitted the change to the current development branch and will be included in the next release. Thanks.