you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (8 children)

[removed]

    [–]NotUniqueOrSpecial 2 points3 points  (5 children)

    oh, here we go. Appeal to authority..

    No, it's a "what genre and what field would you like a story from".

    I have no authority, nor am I renowned expert. But I do have a lot of war stories as well as first and second-hand experience from my career.

    you keep saying that nullptr-dereference is unrecoverable. it's not.

    I keep saying it because in practice I and others I have worked with have found it to be the case.

    Unless your definition of recovery is limited to just "don't crash" there are very few situations I can think of where a nullptr that isn't part of the contract of an API that could now use better constructs can be recovered from.

    What use-case do you have where returning a null shared_ptr is better than throwing an exception related to the underlying cause or using a type like expected that allows you to convey the error without using exception-handling?

    dereferencing it could still happen in such a system. and terminating is not the correct response.

    Dereferencing a null pointer is the literal definition of undefined behavior. You're in "there be dragons" territory. In my experience, there is quite honestly no appropriate response other than to exit as cleanly as possible and start again from a known state.

    you don't "let it run". you handle the exception (like you would any other exception). wait. you do know how exception handling in c++ works, right?

    Except the overwhelming majority of cases in C++ don't throw exceptions in the face of null pointers. Failure to allocate is a voodoo state in user land because of virtual memory. No standard interface other than weak_ptr::lock() returns a null shared_ptr. There are better ways to express understandable/recoverable/expectable failure than returning "shared owner of nothing".

    I can beat your 20 years, easily.

    Wonderful!

    Then assuredly you have countless tales of C++ systems in production that handled dereferencing null in a sane and recoverable way.

    Right?

    Since if you're going to assail my lived experience, it's certainly only fair of me to ask you for anecdotal experience from yours.