From: http://www.cnblogs.com/aigongsi/archive/2012/04/19/2457735.htmlTo summarize all the examples1 in a try, catch, finally statement, if the try statement has a return statement, then the value of the variable in the current try is returned, and
Today when reading the Code book, useful to Try--catch--finally, and then checked the specific attention and application.In simple terms:try {There may be code or code snippets that are wrong}catch{If the code in the try is wrong, an error is
For try Catch Finally, everyone should be familiar with the wording of your contact may be the following several types of notation:
Try catch (you can match multiple catch)
try { } catch (Exception) { throw; } Try finally try { } finally { }
Try { MessageBox.Show ("true");} Catch { MessageBox.Show ("false");} finally { MessageBox.Show ("finally");}NotesThrow exception with throw new exception, catch exception with try: Catch.. Finally
The
Try ... catch is intended to
A common way to use catch and finally is to get and use resources in a try block, handle exceptions in a catch block, and in the finally Frees resources in the block.finally blocks are used to clean up any resources allocated by the try block,
Please read the Embedefinally.java example before running it, observing its output and summarizing it.Source:public class Embededfinally {public static void Main (String args[]) {int result;try {System.out.println ("in Level 1");try
Conclusion:1, regardless of the occurrence of wood anomalies, finally block code will be executed;2, when there is return in the try and catch, finally will still execute;3, finally is executed after the return of the expression after the operation (
Important Conclusions:1. The code in the finally block executes whether or not an exception occurs2. When there is a return in the try and catch, finally will still execute3.finally is performed after the expression operation after return (at this
Conclusion:1, regardless of the occurrence of wood anomalies, finally block code will be executed;2, when there is return in the try and catch, finally will still execute;3, finally is executed after the return of the expression after the operation
There is a return statement in the try and finally block where no exception is thrown in the 1:try block[Java]View PlainCopy
Public static int noexception () {
int i=10;
try{
System.out.println ("I in Try block is" +i);
return-I.;
}
/*While
Int n = 1;// If it is a for loop, for (INT n = 1; n
While (n
{Console. writeline ("the result is {0}", n); // the representation of null!
// Console. Write ("I am: {0}, you are: {1}, We: {2}", a, B, c); pay attention to the format!
Return Statement in try-catch-finally in java, catchreturnfinally
Some questions are raised when using the return statement in the try-catch-finally statement.
Code 1:
static int intc(){ int x =0; try{ x=1; return
Condition 1: If there is no exception in try and return in Try (execution order)tryfinallyreturnCondition 2: If there is an exception in the try and return in Trytry----catch---finallyreturnIn short, finally always execute!Condition 3: There is an
1.try,catch,finallyThe Try keyword is used to enclose logical code that may appear to be abnormal, which is not used alone and must be used with catch or finally. The Java compiler allows a combination of the following three forms:Try...catch ...;
Http://hi.baidu.com/vincentwen/blog/item/b92d0923f1e4c64793580757.html Try Catch finally 1, the code that foresees the possibility of throwing an exception is included in the TRY statement block. 2. If an exception occurs, the execution of the catch
First, let's understand two sets of concepts: Try Catch finally and return1.try Catch finallyFirst say try Catch,(1) A try statement used to enclose a snippet of code that might have an exception. Try is the statement that finds the problem, and
Today, a netizen asked me a question.She said that she had a page where she saved data to the database. If the data was not saved successfully, no error was reported. She did not know what the problem was.I asked her if she had any exception
1. Simple Description: When an external environment problem that cannot be controlled by the program occurs (the file provided by the user does not exist, the file content is damaged, and the network is unavailable ...) JAVA will use exception
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.