What are exceptions? Why is it important to handle exceptions? Discuss different keywords that are used to handle exceptions.

 

An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore, these exceptions are to be handled.


Importance of handling exceptions.

● First, it lets the user know, in a relatively friendly manner, that something has gone wrong and that they should contact the technical support department or that someone from tech support has been notified. As we all know there's a HUGE difference between receiving a rather nasty, tech riddled notice that says something like "Object not set to reference of an object" etc. ... and receiving a nice popup type window that says "There has been an issue. Please contact the helpdesk".

● Second, it allows the programmer to put in some niceties to aid in the debugging of issues. For instance ... in my code, I typically write a custom error handler that takes in a number of parameters and spits back a nice, formatted message that can either be emailed to the helpdesk, stashed in an event log, written to a log file etc.. The error message will contain as much info as I can cram in there to help me figure out what happened, stack traces, function parameters, database calls ... you name it. I like verbose error messages to help me figure out what actually happened. The user never has to see any of it, they get the nice, friendly message above, letting them know that someone can figure out what's going on.


There are five keywords used in Java for exception handling. They are:

i. try

ii. catch

iii. throw

iv. throws

v. finally


The try block

The try block contains the code that might throw an exception. The try block contains at least one catch block or finally block.


The catch block

A catch block must be declared after try block. It contains the error handling code. A catch block executes if an exception generates in corresponding try block.


The throw keyword in Java

● The throw keyword in Java is used to explicitly throw our own exception.

● It can be used for both checked and unchecked exception.


The throws keyword in Java

● The throws keyword is generally used for handling checked exception.

● When you do not want to handle a program by try and catch block, it can be handled by throws.

● Without handling checked exceptions program can never be compiled.

● The throws keyword is always added after the method signature.


The finally block

● The code present in finally block will always be executed even if try block generates some exception.

● Finally block must be followed by try or catch block.

● It is used to execute some important code.

● Finally block executes after try and catch block

Comments

Popular posts from this blog

Suppose that a data warehouse for Big-University consists of the following four dimensions: student, course, semester, and instructor, and two measures count and avg_grade. When at the lowest conceptual level (e.g., for a given student, course, semester, and instructor combination), the avg_grade measure stores the actual course grade of the student. At higher conceptual levels, avg_grade stores the average grade for the given combination. a) Draw a snowflake schema diagram for the data warehouse. b) Starting with the base cuboid [student, course, semester, instructor], what specific OLAP operations (e.g., roll-up from semester to year) should one perform in order to list the average grade of CS courses for each BigUniversity student. c) If each dimension has five levels (including all), such as “student < major < status < university < all”, how many cuboids will this cube contain (including the base and apex cuboids)?

Suppose that a data warehouse consists of the four dimensions; date, spectator, location, and game, and the two measures, count and charge, where charge is the fee that a spectator pays when watching a game on a given date. Spectators may be students, adults, or seniors, with each category having its own charge rate. a) Draw a star schema diagram for the data b) Starting with the base cuboid [date; spectator; location; game], what specific OLAP operations should perform in order to list the total charge paid by student spectators at GM Place in 2004?

Explain network topology .Explain tis types with its advantages and disadvantges.