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.
Welcome to basic error handling with PHP.
I'm happy to help you on your journey to becoming an awesome programmer.
If you use PHP at all, you've probably run into the white screen of death.
A blank white page with nothing on it.
This is PHP's way of saying, I don't know how to process this script.
So how do you start figuring out what's wrong?
There are two fundamental types of errors in software.
First we have the system errors.
These are the logic errors in your code.
These errors can be prevented to a very large degree by careful programming.
Next we have external errors.
These are errors related to 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 or many more.
You can't always avoid these types of errors.
But their impact can be mitigated.
The better you prepare your code for
external errors, the less these errors will negatively affect your program.
In this workshop, we'll cover some of the most common ways of handling errors and
show you how to start finding the errors in your code.
This is not an exhaustive account of error handling or debugging in PHP.
But it is intended to get you started on your journey to understanding and
fixing your code.
HTML is very forgiving.
The browser ignores your mistakes and tries the best it can to render the page.
PHP on the other hand, is stricter and much less forgiving.
Any syntax errors can result in the page not loading correctly.
Only part of the page may load or you may see the white screen or
the browser's error page.
When dealing with errors, there are a few steps we should consider
when deciding how we want to handle the errors.
Logging allows errors to be stored and reviewed from a log file.
And reports or alerts can make people aware of errors as they come up.
Displaying the error allows the error to be shown to the developer and or
user when the program is being executed.
The type of action needed will differ for each situation.
A certain level or certain type of error could log a ticket,
send an email or alert an on call team.
Most of the time ignoring an issue is not the way you want to handle things.
But sometimes decisions are made to ignore certain levels or specific errors.
A company could choose to define in their own best practices,
not to declare a variable until it has first being used.
Sometimes, an error may be ignored while other changes are being made.
We could choose to ignore an issue with reading a file, because the code
is being changed in such a way that the file will no longer be used.
But ignoring errors can be very dangerous and hard to fix later on.
So try to avoid this when possible.
I'm excited to get started.
So let's take a look at what we need to do to start finding and
doing something with these errors.
You need to sign up for Treehouse in order to download course files.Sign up