1. What is a try block?A try block is a block of code that can produce an exception, and a try block may follow a catch block or a finally block, or both.The semantics of the try block:try{ //statements that could cause an exception}2. What is a
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
Public void mymothed (){Try{// Do somethingInt x = 5/0; // It is divided by 0. An error occurs here.}Catch (systemexception){// Do something here}Catch (dividebyzeroexception){// Here is the solution to the error of division by 0}Catch (exception){//
I am basically illiterate in terms of data Literacy. Today, I saw someone else's
Article I think it's okay. I am not very familiar with the principle, but I 'd like to explain it first.
The original article is as follows: (the replacement part is
From the compiler perspective, exceptions in Java can be divided into two types: checked exceptions and unchecked exceptions. For checked exceptions such as IO operations, the compiler requires that you set the try/catch statement block. In eclipse,
Throw new exception (string, exception)
Throw new exception (string)
Throw explicitly throws an exception.
Msdn: exception (string, exception) initializes a new instance of the exception class by specifying the error message and referencing
For a shutdown operation, it is best to use the following block of statements:InputStream in= ...; try{ try{ //some statemenet }finally{ //close stream in.cloase (); } } catch (Ioexpeactin e) {
In the stored procedure of SQL Server, according to the requirements of the business logic, sometimes a custom exception needs to be thrown #ProgramCapture and perform corresponding processing.SQL Server throws a custom exception and is simple, like
1. Background Introduction
Why do you want to do exception handling?
For a computer program, no one can guarantee that it will run without error, the main source of error is the following:
Code Error
User illegal input
Device errors
1.Java ExceptionIn the process of using computer language for project development, even if the programmer writes the code perfectly, there are still some problems in the running of the system, because many problems can not be avoided by the code,
Mxs&vincene─╄ovё&0000021─╄ovёmxs&vinceneMxs&vincene─╄ovё: Today is very cruel, tomorrow is more brutal, the day after tomorrow is very good, but most people die in the evening, only those real heroes can see the sun after the day.Mxs&vincene─╄ovё:we
1. Basic Concepts
By data type: Java has two kinds of byte stream and character streams:
BYTE throttling: Inputstream/outputstream
Character streams: Reader/writer
When a byte stream is read, a byte is returned when it is read.
The character stream
1 GuideTry... Catch... FinallyI'm afraid it's a familiar statement, and it seems easy to understand logically. However, the lessons I personally learned tell me that this is not as simple and obedient as I imagined. Believe it? Let's take a look
Try{
...Response. Redirect ("/Mymaimai. aspx");...}Catch (exception E){//Exception Handling
}
Use the preceding statement , Whether or not exceptions exist , All Catch In , Always show "" Failed "" Will throw system.
Http://www.cnblogs.com/jkswjw/archive/2009/03/05/1403639.html
Try{
...Response. Redirect ("/Mymaimai. aspx ");...}Catch (exception E){// Exception Handling
}
If you use the preceding statements, system. Threading. threadabortexception will be thrown
A code segment that uses # If to prevent compilation of the try/catch keyword and throws exceptions in the debug state, the try/catch keyword is compiled, and the program can intercept exceptions.
Using this code facilitates debugging. Re Re
An example in Mina is as follows:
@ Override public void filterwrite (nextfilter, iosession session, writerequest) throws exception {Object Data = writerequest. getmessage (); If (Data instanceof iobuffer) {write (Session, (iobuffer) data);} else {
Try
{
...
.. Response.Redirect ("/mymaimai.aspx"); ..
}
catch (Exception e)
{
//exception handling
}
Using the above statement, regardless of whether there is an exception, the catch will be executed, always show "" failed ", will throw
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.