Your SlideShare is downloading. ×
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Exception handler
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Exception handler

1,672

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,672
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Exception Handler
  • 2. Questions # 1
    • Define Exception, exception handler, raising an exception, disabling an exception, continuation and built in exception.
  • 3. Answer
    • Exceptions are errors detected by hardware, such as disk read errors and unusual conditions such as end files. These are also unusual events , erroneous or not, that is detectable either by hardware or software and that may require special processing.
  • 4. Answer
    • Exception Handler is a code unit that monitors the special processing that may be required by the detection of an exception or also called exception handling.
    • Raising an Exception An object raises an exception when it has trapped an error. An object raises an exception by sending itself the "raiseException" message, passing an error number as a parameter.
  • 5. Answer
    • Continuation is the question of control continuation after handler execution for an exception handler executes either control can transfer to somewhere in the program outside of the hadler code, or program execution can simply terminate.
    • Built in Exception is an exception that is constructed as part of the language and is not detachable.
  • 6. Question # 2
    • What are the design issues for an exception handling?
  • 7. Answer
    • 1. Form – a choice between having handlers that are complete programs units or handlers that are code segments. They may be embedded in the units that caused the exception they are to handle or they may be embedded in a different unit, such as the unit that called the one in which the exception is raised.
  • 8. Answer
    • 2. How an exception occurrence is bound to an exception handler – This occurs in two different levels, On the unit level, there is the question of how the same exception being raised at different points in a unit can be bound to different handlers within the unit. It should be possible to bind the exception that can be raised by particular statements to particular handlers, even though the same exception can be raised by many different statements. At the higher level, the binding question arises when there is no exception handler local to the unit in which the exception is raised. If exceptions are propagated, a single handler might handle the same exceptions raised in several program units, which may require the handler to be more general than one would prefer.
  • 9. Answer
    • 3. Whether the binding of exceptions to handlers is static or dynamic , that is , whether binding depends on the syntactic layout of the program or on its execution sequence. As it is in other language constructs, static binding of exceptions is easier to understand and implement than dynamic binding.
  • 10. Answer
    • 4. If users are allowed to define exceptions, how are there exceptions specified? The usual answer is to require that they be declared in the specifications parts of the program units in which they can be raised.
    • 5. Whether built in exceptions can be raised explicitly by the user program. This can be convenient if there are software – detectable situations in which the user would like to use a built- handler.
  • 11. Answer
    • 6. Whether hardware-detectable errors should be treated as exceptions that could be handled by user program. It not, all exceptions obviously are software-detectable. A related question is whether there should be any built in exceptions.
    • 7. Whether exception, either built in or user-defined, can be temporarily or permanently disabled.
  • 12. Question # 3
    • What does it mean for an exception to be bound to an exception handler?
  • 13. Answer
    • If the block or unit in which an exception is raised does not have a handler for that exception, the exception is propagated elsewhere to be handled – Procedures - propagate it to the caller – Blocks - propagate it to the scope in which it appears – Package body - propagate it to the declaration part of the unit that declared the package (if it is a library unit, the program is terminated)
  • 14. Answer
    • – Task - no propagation; if it haandler, execute it; in either case, mark it "completed --- Sa JAVA Binding an exception to a handler is simpler in Java than it is in C++ – An exception is bound to the first handler with a parameter is the same class as the thrown object or an ancestor of it • An exception can be handled and rethrown by including a throw in the handler (a handler could also throw a different exception)
  • 15. Question # 4
    • What is the parent class of most Java user-defined exception classes?
  • 16. Answer
    • Throwable class. Based on the book, All Java exceptions are objects of classes that are descendants of the Throwable class
  • 17. Question # 5
    • How can an exception handler be written in Java so that it handles any exceptions?
  • 18. Answer
    • To ensure that exceptions can be thrown in a try clause are always handled in a method, a special handler can be written that matches all exceptions that are derived from Exception simply by defining the handler with an Exception type parameter as in catch (Exception genericObject) { … }
  • 19. Question # 6
    • What is the difference between a C++ throw specifications and a Java throws clause?
  • 20. Answer
    • 1. A C++ program can throw any type defined in the program or by the system. In Java, only objects that are instances of Throwable or some class that descends from it can be thrown.
    • 2. A C++ program unit that does not include a throws clause can throw any exception, which tells the reader nothing. A Java method that does not include throws clause cannot throw any checked exceptions that it does not handle. Therefore, the reader of a Java method knows from its header what exceptions it could throw but does not handle.
  • 21. Answer
    • 3. The addition of the finally clause is great convenience in certain situations. It allows cleanup kinds of actions to take place regardless of how a compound statement terminated.
    • 4. The Java run-time system implicitly throws a variety of exceptions, such as for array indices out of range and null reference variable accesses, which can be handled by any user program. A C++ program can handle only those exceptions that it explicitly throws.
  • 22. Question # 7
    • What is the difference between checked and unchecked exceptions in Java?
  • 23. Answer
    • Checked exceptions are carried out or executed whenever there is an error in the syntax and programming-side while unchecked exceptions hold the errors that might occur during user or data interaction.
  • 24. Question # 8
    • Can you disable a Java exception?
  • 25. Answer
    • There are exceptions in Java that are automatically invoked when a data-specific error occurs. These exceptions are also called checked exceptions. They cannot be disabled as they are built-in with the Java API. But if you are using an unchecked exception, you may disable it intentionally or unintentionally by using a break; statement just before a line that might throw an exception.
  • 26. Question # 9
    • What is the purpose of the Java finally clause?
  • 27. Answer
    • Purpose: To specify code that is to be executed, regardless of what happens in the try construct
  • 28.
    • Kristine Ancheta
    • Stephanie Rosanna Blanza
    • Desney Ann Caracot
    • Roshe Nikhka de Guzman
    • Rhys Anton Gabion
    • Erick Lester Sumugat
    • Carlo Mar

×