From the course: Learning Julia

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Exception handling

Exception handling - Julia Tutorial

From the course: Learning Julia

Start my 1-month free trial

Exception handling

- [Instructor] Even when your code is solid and well written, your programs will encounter unexpected conditions. To handle these conditions, we use something called exception handling. This is a pretty common feature of other programming languages, and Julia provides it as well. Let's go ahead and open up the exceptions_start file and you can see that we have some simple code here that performs a square root calculation. So there's a variable, and we give it a value. We call the square root function, and we print the result. So let's go ahead and run that, and you can see that the square root of nine is three. But now let's go back and change that value to a negative number and then let's save and run it again. And you can see now that we're getting an error because you can't perform a square root calculation on a negative integer number. You have to call it with a complex argument. So you can see that we're getting this domain error here. Now this error causes our program to exit in…

Contents