TAILIEUCHUNG - Sams Teach Yourself Java 6 in 21 Days 5th phần 4

Ví dụ, lớp parseInt () phương pháp trong lớp Integer có thể được sử dụng với một đối số chuỗi, trả về một đại diện int của chuỗi đó. Tuyên bố sau đây cho thấy làm thế nào parseInt () phương pháp có thể được sử dụng:Trong tuyên bố trước đó, giá trị String "42" là được trả về bởi parseInt () là một số nguyên với một giá trị là 42, | Simpo PDF Merge and Split Unregísteredverson -YHttp yWWW exceptions. It could even throw no exceptions at all. That means that you can have the following two class definitions and things will work just fine public class RadioPlayer public void startPlaying throws SoundException body of method public class StereoPlayer extends RadioPlayer public void startPlaying body of method The converse of this rule is not true A subclass method cannot throw more exceptions either exceptions of different types or more general exception classes than its superclass method. Creating and Throwing Your Own Exceptions There are two sides to every exception the side that throws the exception and the side that catches it. An exception can be tossed around a number of times to a number of methods before it s caught but eventually it will be caught and dealt with. Who does the actual throwing Where do exceptions come from Many exceptions are thrown by the Java runtime or by methods inside the Java classes themselves. You also can throw any of the standard exceptions that the Java class libraries define or you can create and throw your own exceptions. Throwing Exceptions Declaring that your method throws an exception is useful only to your method s users and to the Java compiler which checks to make sure that all your exceptions are being handled. The declaration itself doesn t do anything to actually throw that exception should it occur you must do that yourself as needed in the body of the method. You need to create a new instance of an exception class to throw an exception. After you 7 have that instance use the throw statement to throw it. 198 Simpo P DFeMergeandr Split Unregistered Version - http Here s an example using a hypothetical NotInServiceException class that is a subclass of the Exception class NotInServiceException nise new NotInServiceException throw nise You can throw only objects that implement the Throwable interface. Depending on the .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.