I. Error HandlingException Handling: unexpected, unexpected, occurs during the running of the program. Use an exception to change the normal process of the script.A new important feature in PHP5Copy codeThe Code is as follows:If (){} Else {}Try {}
1 First of all, Try,catch.
$path = "D:\\\\in.txt";
Try//Detect exceptions
{
File_open ($path);
}
catch (Exception $e)//Catch exception
{
echo $e->getmessage ();
}
function File_open ($path)
{
if (!file_exists ($path))//If the file cannot be found,
1. What is an exception? What is the difference between an exception and an error?
1. Exception: program operation is not consistent with expectations, and errors are two different concepts!2. Throwing and catching exceptions3. Multiple catch
In addition to the new features mentioned above, try catch in Java 7 is a simple example in this article. In fact, there are still many points to note. First, let's look at a typical code:
Two exception classes are introduced:
Java code
Public
PhP5 has an exception, which is much better than before. Let's take a note below.
1 first, try and catch
$ Path = "D: \ in.txt ";Try // detect exceptions{File_open ($ PATH );}Catch (exception $ e) // catch an exception{Echo $ e-> getmessage
Java's exception handling mechanism can make the program have excellent fault tolerance and make the program more robust. The so-called exception is the problem that prevents the current method or scope from continuing to execute, and when the
In Java 7, the catch code block was upgraded to handle multiple exceptions in a single catch block. If you are capturing multiple exceptions and they contain similar code, using this feature will reduce code duplication. Here is an example to
PHP Error Handling
When we develop the program, sometimes there is a problem with the program, we can use the following methods to find out the error.
Development phase: Output all error reports at development time, which will help us to debug the
Exception ):Exception Handling is used to change the normal process of the script when a specified error (exception) occurs.
When an exception is triggered, it usually occurs:
The current Code status is saved.
Code execution is switched to a
Thinking in Java --- Exception Handling Mechanism, thinkingjava ---
The exception handling mechanism of java can make the program have excellent fault tolerance and make the program more robust. the so-called Exception refers to the problem of
PHP custom exception processor usage methods. The following four sections of code handle exceptions are simple applications (non-production environments) in my waylife project, which are neither robust nor beautifying, but the SNS project has been
Create function with an exception
function Checknum ($number)
{
if ($number >1)
{
throw new Exception ("Value must be 1 or below");
}
return true;
}
Trigger exception
PHP exception handling knowledge
// Create function with an exception
Function checkNum ($ number)
{
If ($ number> 1)
{
Throw new Exception ("Value must be 1 or below ");
}
Return
Unusual exercises:The teacher uses the computer for class.Start thinking about the problems that arise in class.For example, the problem isComputer blue screen.The computer smokes.To describe the problem, encapsulate it as an object.However, when
Java-10.3 custom exception types
In this section, we will briefly discuss the custom exception types.
Generally, the exception types defined in java are enough for us to use. However, we need other custom types in actual operations.
In the exception
Why do we need to talk about exception handling in the J2EE project? Many java beginners may want to say: "exception handling is not a try .... Catch... Finally? Everyone will do that !". This is what I think when I was a beginner in java. In a
What is an exception?PHP 5 provides a new approach to object-oriented error handling.Exception handling is used to change the normal process of a script when a specified error (exception) condition occurs. This condition is called an exception.When
1, Exceptions-OverviewException: This is when the program is running in an unhealthy situation.The origin of the anomaly: The problem is also a concrete thing in real life,It can also be described in the form of a Java class and encapsulated as an
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.