lemme learn ya a thing or two.

back at it again.

Today we'll be going over how we can handle how errors work within our Lisp dialect.


First thing we can easily notice is how if we do something such as dividing by zero, the [interpreter] program crashes.



What are we going to do about this? Well thankfully, C allows us to properly handle errors. We're first going to use enum to enumerate all possible error types (or rather, the most common ones we'll get), and use lval to define our Lisp values. Go ahead and place this after our initial char* declaration.



While we're at it, let's create a new struct regarding lval.



Perfect, but we'll also need to declare some type stuff. The first thing will be to create a new error type, and a new number type, then print our Lisp values.



As you can tell, you can have a lot of fun here. Just pay attention what the error prints pertain to.


Now that we have our errors ready, let's define when they can be used.



Cool. Now, your code should look something like this:



Now run, and try to intentionally cause an error. Go ahead, try. Nerd.



Good stuff.


Tomorrow, we'll start to wrap things up by extending our language further.




tutorials on whatever, daily. doesn't have to be tech-related, but it mostly is.