As well as changing the type signatures we need to change the functions such that they work correctly upon encountering either an error as input, or a number as input.

    In our eval_op function, if we encounter an error we should return it right away, and only do computation if both the arguments are numbers. We should modify our code to return an error rather than attempt to divide by zero. This will fix the crash described at the beginning of this chapter.

    You’ll notice that for division to check if the second argument is zero we use a question mark symbol ?, followed by a colon . This is called the ternary operator, and it allows you to write conditional expressions on one line.

    It works something like this. <condition> ? <then> : <else>. In other words, if the condition is true it returns what follows the ?, otherwise it returns what follows :.

    We need to give a similar treatment to our eval function. In this case because we’ve defined to robustly handle errors we just need to add the error conditions to our number conversion function.

    In this case we use the strtol function to convert from string to long. This allows us to check a special variable errno to ensure the conversion goes correctly. This is a more robust way to convert numbers than our previous method using atoi.

    And we are done! Try running this new program and make sure there are no crashes when dividing by zero.