tailieunhanh - Java™ How to Program ( Deitel - Deitel) - Phần 23
Tham khảo sách 'java™ how to program ( deitel - deitel) - phần 23', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Common Programming Error Each catch block can have only a single parameterspecifying a comma-separated list of exception parameters is a syntax error. Common Programming Error It is a compilation error to catch the same type in two different catch blocks in a single try statement. An uncaught exception is an exception that occurs for which there are no matching catch blocks. You saw uncaught exceptions in the second and third outputs of Fig. . Recall that when exceptions occurred in that example the application terminated early after displaying the exception s stack trace . This does not always occur as a result of uncaught exceptions. As you will learn in Chapter 23 Java uses a multithreaded model of program execution. Each thread is a parallel activity. One program can have many threads. If a program has only one thread an uncaught exception will cause the program to terminate. If a program has multiple threads an uncaught exception will terminate only the thread where the exception occurred. In such programs however certain threads may rely on others and if one thread terminates due to an uncaught exception there may be adverse effects to the rest of the program. Termination Model of Exception Handling If an exception occurs in a try block such as an InputMismatchException being thrown as a result of the code at line 25 of Fig. the try block terminates immediately and program control transfers to the first of the following catch blocks in which the exception parameter s type matches the type of the thrown exception. In Fig. the first catch block catches InputMismatchExceptions which occur if invalid input is entered and the second catch block catches ArithmeticExceptions which occur if an attempt is made to divide by zero . After the exception is handled program control does not return to the throw point because the try block has expired which also causes any of its local variables to be lost . Rather control resumes after the last catch
đang nạp các trang xem trước