‫Hello, everybody, and in this lecture, we're going to learn how to handle program crashes, so essentially
‫a program crashes when a exception is thrown.
‫So first, let's go to Firefox's here and take a look at these exceptions.
‫So we have divide by zero, breakpoint overflow.
‫Granted, some of these aren't us.
‫However, we will just have them that way in our colonel any exception at all and will terminate the
‫process.
‫So you can see there's quite a few to handle.
‫OK, we'll treat them all the same.
‫We'll just terminate our program.
‫We won't have any special use cases.
‫Uh, if there's any exception thrown at all, we will terminate the program.
‫It's as simple as that.
‫And we already have our process terminated function from last lecture.
‫So we have something we can work with.
‫OK, so just had the Visual Studio code and I want us to go to it id to see.
‫OK, and just scroll up here until you see ID in it and essentially we're just going to go void it,
‫handle exception.
‫OK, and in this situation we're going to go process terminates and we are going to have to include
‫process up here guys.
‫And this task process is not process process, start a task process, stage process, terminate tasks,
‫current process.
‫So that'll terminate the current process that's running.
‫OK, you'll notice here we use TASC current process and not process current.
‫I've explained why we do that in previous lectures before process current.
‫The process current function will get the current active process, not the current process of the task
‫that's currently running.
‫OK, so if you look at the keyboard lecturer again, you know, I explained that in detail in that lecture
‫because of how Keibel push is different from keyboard pop.
‫So yeah, we terminate the current tasks process, which is perfect that that kills the program.
‫But now we have nothing to return to.
‫We can't return from this exception.
‫Right.
‫I mean, we're going to run code that doesn't exist anymore.
‫Uh, so what we do is we go test next and we haven't created that function yet.
‫But essentially this will grab the next task and and drop the privilege level back into use the land
‫and execute that task.
‫That's next on the list.
‫So we're going to implement that now.
‫So just go to task double C in the task directory and we're just going to go in it task next and then
‫we're just going to go struct task.
‫Next task equals task at next.
‫And if the next task is no, we're going to panic.
‫No more tasks.
‫OK, uh, if the next task is not null, then we're just going to essentially go tasks switch next task
‫and task for turn task for the next task, I should say.
‫Register's next task registers and we're going to put an ampersand there and obviously we won't return
‫from this function.
‫So it should actually be void.
‫OK, uh, so yeah, as you know, task return will drop us back in to use the land and begin executing
‫at those registers of the of the next task here.
‫OK, so just copy and paste that into task of the Hajj so that accessible.
‫OK, perfect.
‫Now just good to see again.
‫We can see how it handle exception functions made but we haven't linked it at all.
‫OK, so, so we need to actually do that.
‫So just by here we're going to say I equals zero eight below zero x twenty.
‫So we're going to have all the exceptions.
‫OK, and we're just going to go ID register, interrupt, callback, OK.
‫And we're going to provide AI for the interim number and then our callback function will be ADT handle
‫exception.
‫So that will ensure that we map all exception interrupts to this function and this function will terminate
‫the process and get the next task.
‫If you want to improve this implementation, you might create a process crash function, which will
‫then be also responsible for loading, uh, another program that tells the user why the program crashed.
‫OK, so that's a potential way of showing what went wrong.
‫However, we're not going to do that here.
‫We'll just terminate.
‫The process and switch to the next task, that will be absolutely fine for us, so we're just going
‫to go make clean bill that S.H..
‫And we can see that Kampala's absolutely fine.
‫So when now going to test this, OK, so I want us to go to programs blank blanked out, see and we're
‫going to go to PTA equals char zero zero zero and we're going to try and set that to something.
‫OK, now the page tables won't allow us to do this, OK, because we don't have access to this page.
‫So for sure it's going to throw an exception and hopefully our program crashes, but we will find out
‫now for sure.
‫OK, so just do another make clean bill to this age.
‫You'll notice I always do a full rebuild.
‫It's best to be safe.
‫You know, sometimes those mistakes that sometimes make mistakes in the makefile and maybe it doesn't
‫check for headful changes or something.
‫Right.
‫So it's best to make clean all the time.
‫So here we're going to go.
‫Kumu systemis three eight six.
‫How do I stop.
‫And we can see is loaded.
‫Let's now go Blankfort of testing so we can see it.
‫Prince Blanket often testing and then we're back to the prompt.
‫Now why are we back to the prompt.
‫Because our program crashed.
‫That's why it crashed and because it crashed, it caused us to terminate the process and go back to
‫the next run task and the next running task in this case was the shell.
‫So let's make this a little better.
‫Go to process, start see in process, terminate or just going to just put a little message for yourself.
‫Process was terminated just as an example.
‫Now, this is very ugly in real life.
‫You would never do it like this.
‫You would never print a message like that.
‫Right.
‫You would find some way of signaling the message back to the terminal.
‫You wouldn't just print like that.
‫That's very dirty.
‫But I just want to do that just so I can show you exactly what's going on.
‫Right.
‫And we can see print doesn't exist.
‫You just you print because we're in kernel and I forgot and we're going to go see the been kumu
‫flunked out of testing and there we go.
‫You can see process was terminated.
‫OK, so you can see that, that, that's working.
‫OK, we caused an exception.
‫Our process gets terminated.
‫I'm going to get rid of that message now because like I said, it's bad practice to just print that
‫out like that.
‫You know, if you really want to let the process know something went wrong, then you should find a
‫way of signaling the shell.
‫And there's many different ways to do that.
‫One way would be making our invoke commands somehow block and receive the return result from the program
‫that it started.
‫And, you know, you can you can be very creative in how you do that.
‫So thanks for watching this lecture, guys.
‫And we now have, uh, the handling of process crashes.
‫So congratulations.