next-exp / nexus

Geant4 simulation framework of the NEXT Collaboration
5 stars 55 forks source link

Add protection for wrong keys in object factory #256

Closed gonzaponte closed 4 months ago

gonzaponte commented 4 months ago

If the wrong name is used for, say, a generator, the user gets a wild segfault with zero information about what went wrong. This PR adds protection against bad strings and provides a more helpful message.

Bear in mind that part of the message is compiler-dependent. There are no guarantees that typeid(x).name() gives a human-readable output. Thankfully, most compilers do provide a sensible output, so this might be a good enough compromise between simplicity and correctness.

I also added a test that verifies that the exception is raised.