Is there a good reason why this throws a seg violation:
w.pdf("gaus")->Print(); // Niiice
w.pdf("gaus_with_spelling_mistake")->Print(); // Throws segmentation violation
and not something like “gaus_with_spelling_error” not found in workspace “w” in line “xx”? It is really hard to debug.
It’s your job to protect your code against using a null pointer (returned by RooWorkspace::pdf in this case).
I guess my question is, is there a good reason why RooWorkspace::pdf does not throw a warning message/exception when returning a NULL pointer?
You may be simply “testing” if some RooWorkspace object has some specific pdf / var / cat / arg / data / … (and if yes, you use it, but if not, you try to “retrieve” another one) -> so a returned null pointer is not an error, it simply means that something does not exist.
Ok. Now I also know where to look for typos next time I get Seg violations.
Thanks again for the answer
Actually this is a much more general problem.
I’ve many times seen source code which contains something like this:
and the “intermediate” pointers (returned by “GetSomething” and “GetSomethingElse”) are not checked at all (so if any of them is a null pointer then it will usually result in a SIGSEGV, but not always -> sometimes you will simply get something screwed but your code will happily proceed).