Sale notes online your Nr 1 Resource,for passing Exam at VCU
Sale notes online your Nr 1 Resource,for passing Exam at VCU
Provide well Written Notes Of Object Oriented Programming Class Notes For College Student , C++ Programming
All for this textbook (4)
Written for
B tech IT
All documents for this subject (19)
Seller
Follow
vengatedits
Content preview
EXCEL ENGINEERING COLLEGE
(Autonomous)
COMPUTER SCIENCE AND ENGINEERING
III Semester
20CS302 – OBJECT ORIENTED PROGRAMMING
Regulations 2020
Question Bank with Answer Key
UNIT – III (APPLETS, EXCEPTION HANDLING AND I/O)
PART- A
Q.No Questions
Define Exception.
1 A Java exception is an object that finds an exceptional condition occurs from a piece of code.
An exception object is created and thrown to the method from the code where an exception is found.
Recall the purpose of exception handling mechanism.
The main purpose of exception handling mechanism is used to detect and report an “exceptional
circumstance” so that necessary action can be taken. It performs the following tasks
Find the problem(Hit the exception)
2
Inform that an error occurred(throw the exception).
Receive the error information(Catch the exception)
Take corrective actions(Handle the exception)
What are the types of exceptions?
There are two types of exceptions
3 Predefined Exceptions-The Exceptions which are predefined are calledpredefined exceptions
Userdefined Exceptions- The Exceptions which are defined by the userare called userdefined exceptions
How the exception handling is managed?
Java exception handling is managed via five keywords.
try
4 catch
throw
throws and
finally
Write down the general form of an exception-handling block.
The general form of an exception-handling blocktry
{
// block of code to monitor for errors
}
catch (ExceptionType1 exOb)
5 {
// exception handler for ExceptionType1
}
catch (ExceptionType2 exOb)
{
// exception handler for ExceptionType2
, }
// ...
finally
{
// block of code to be executed after try block ends
}
List out the two subclasses under Throwable class.
Throwable is a superclass for all exception types. Thus, Throwable is at topof the exception hierarchy.
There are two subclasses under Throwable class.
6
Exception
Error
What is an Error?
The another subclass is by Error, which defines exceptions that are notexpected to be caught under
normal circumstances by your program.
7 Exceptions of type Error are used by the Java run-time system to indicateerrors having to do with the run-
time environment, itself.
Eg: Stack overflow is an example of such an error.
Identify the situation where we need to use multiple catchclauses.
In some situation, more than one exception can occur by a single piece of code.
To handle this situation, we can use two or more catch clauses, each catching a different type of exception.
8 When an exception is thrown, each catch block is executed in order, and the first one whose type matches
that exception is executed.
After one catch block executes, the others are bypassed, and continues after the try/catch block.
Why we need to use nested try statements.
The try statement can be nested. That is, a try statement can be inside the block of another try.
Each time a try statement is entered, the context of that exception is pushed on the stack.
If an inner try statement does not have a catch handler for a particular exception, the stack is unwound
9
and the next try statement’s catch handlers are inspected for a match.
This continues until one of the catch statements succeeds, or until all of the nested try statements are
exhausted. If no catch statement matches, then the Java run-time system will handle the exception.
Write down the use of throws clause.
Using throws clause, We can list the types of exceptions that a method might throw.
10 The exceptions which are thrown in a method might be using throws clause. If they are not, a compile-time
error will result.
Give the use of finally clause.
Finally creates a block of code that is to be executed after a try/catch block has completed its execution.
The finally block will execute if an exception is thrown or not thrown.
11
The finally clause is optional.
Each try block requires either one catch or a finally clause
Define Unchecked Exception.
These are the exceptions that are not checked at compiled time.
12 In C++, all exceptions are unchecked, so it is not forced by the compiler to either handle or specify the
exception.
It is up to the programmers to be civilized, and specify or catch the exceptions.
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller vengatedits. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $12.29. You're not tied to anything after your purchase.