From the course: Advanced SQL for Application Development

Unlock the full course today

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

Error trapping

Error trapping

From the course: Advanced SQL for Application Development

Start my 1-month free trial

Error trapping

- [Instructor] So there are many ways things can go wrong with database errors. Fortunately the way we handle them is pretty standard. So let's walk through an example. We're going to make a connection and use an invalid password and we'll see how to trap for that kind of error. So the first thing I want to do is import my database connection library and I also am going to be using environment variables, so import the OS package. And just to show you that I'm using invalid password, I'm going to set up a couple of environment variables for username and we'll set that to Postgres. We'll also have an environment variable for password. Instead of using the actual password, I'll just make something up, invalid password, and we'll save that out to the environment variable. And let's grab those environment variables and save them in local variables. So we'll say user and we'll grab the username environment variable and password.…

Contents