Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Dealing with Errors3:16 with Alena Holligan
Even the most seasoned professional mis-types or forgets something. Sometimes resources your program requires may not be accessible; or, a user may interact with our application in a way we never intended. So how do we find and address those issues?
Installing a Local Development Environment
Fundamental Types of Errors in Software:
1. Internal Errors: These are the logic errors in your code. These errors can be prevented to a very large degree by careful programming.
2. External Errors: These are errors related to the interactions with the world outside your code. These include things such as failing to open a file or database, dropping the network connection, being unable to load a certain PHP module and more. You can't always avoid these types of errors , but their impact can be mitigated. The better you prepare your code for these external errors, the less these errors will negatively affect your program.
Addressing the Issues
1. Log or Report the Error: Store errors in a log file and alerts people as they come up.
2. Display the Error: Show errors to a developer and/or user when the program is being executed.
3. Act on the Error: Certain levels, or types of errors can trigger different tasks, such as logging a ticket, sending an email or alerting an on call team.
4. Ignore the Error: DANGER! Ignoring errors can be very dangerous and hard to fix later, so try to avoid this when possible.
[MUSIC] 0:00 Welcome to basic error handling with PHP. 0:04 I'm Alena. 0:07 I'm happy to help you on your journey to becoming an awesome programmer. 0:08 If you use PHP at all, you've probably run into the white screen of death. 0:12 A blank white page with nothing on it. 0:16 This is PHP's way of saying, I don't know how to process this script. 0:19 So how do you start figuring out what's wrong? 0:24 There are two fundamental types of errors in software. 0:27 First we have the system errors. 0:30 These are the logic errors in your code. 0:33 These errors can be prevented to a very large degree by careful programming. 0:35 Next we have external errors. 0:40 These are errors related to interactions with the world outside your code. 0:42 These include things such as failing to open a file or database, dropping 0:46 the network connection, being unable to load a certain PHP module or many more. 0:51 You can't always avoid these types of errors. 0:56 But their impact can be mitigated. 0:59 The better you prepare your code for 1:01 external errors, the less these errors will negatively affect your program. 1:03 In this workshop, we'll cover some of the most common ways of handling errors and 1:09 show you how to start finding the errors in your code. 1:13 This is not an exhaustive account of error handling or debugging in PHP. 1:16 But it is intended to get you started on your journey to understanding and 1:21 fixing your code. 1:26 HTML is very forgiving. 1:28 The browser ignores your mistakes and tries the best it can to render the page. 1:29 PHP on the other hand, is stricter and much less forgiving. 1:34 Any syntax errors can result in the page not loading correctly. 1:39 Only part of the page may load or you may see the white screen or 1:43 the browser's error page. 1:47 When dealing with errors, there are a few steps we should consider 1:49 when deciding how we want to handle the errors. 1:52 Logging allows errors to be stored and reviewed from a log file. 1:56 And reports or alerts can make people aware of errors as they come up. 2:01 Displaying the error allows the error to be shown to the developer and or 2:06 user when the program is being executed. 2:10 The type of action needed will differ for each situation. 2:13 A certain level or certain type of error could log a ticket, 2:18 send an email or alert an on call team. 2:22 Most of the time ignoring an issue is not the way you want to handle things. 2:26 But sometimes decisions are made to ignore certain levels or specific errors. 2:31 A company could choose to define in their own best practices, 2:37 not to declare a variable until it has first being used. 2:41 Sometimes, an error may be ignored while other changes are being made. 2:45 We could choose to ignore an issue with reading a file, because the code 2:49 is being changed in such a way that the file will no longer be used. 2:54 But ignoring errors can be very dangerous and hard to fix later on. 2:59 So try to avoid this when possible. 3:05 I'm excited to get started. 3:08 So let's take a look at what we need to do to start finding and 3:10 doing something with these errors. 3:13
You need to sign up for Treehouse in order to download course files.Sign up