How do exceptions occur in the real world? That is represented in our everyday lives. Try to separate yourself from the actual programmatic code and look

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
How do exceptions occur in the real world? That is represented in our everyday lives. Try to separate yourself from the actual programmatic code and look for the high-level concepts in your day-to-day life or in your discipline. Please write a response on how problems in life may occur and how they relate to programmatic exceptions, try-catch blocks, and finally statements. Feel free to use industry-specific examples and be creative.
Expert Solution
Step 1

Solution- What causes exceptions in the real world. That can be seen in the way we live our daily lives. where we have made an effort to distinguish this exception from the real programmatic code, The topics include examples from everyday life. The answer to the problem is a discussion of potential life difficulties and how they connect to programmatic exceptions, try-catch blocks, and finally statements.

Let's examine a real-world illustration. Consider a stretch of road that has a tiny bridge with a low weight limit. The bridge might collapse if a vehicle that weighs more than it can support crosses it. To put it plainly, the driver's condition would become unusual.

The transportation department puts up warning signs on the highway in advance of any problems to prevent/avoid this.

When a driver sees the warning sign, they weigh their car against the limit for the bridge. The driver uses a bypass route if the car is too heavy.

The transportation authorities first gave truck drivers the option to alter their route if necessary, then informed them about the dangers on the main road, and then warned them that the bridge should not be utilised in certain circumstances.

Java uses exceptions as a means of preventing and resolving exceptional occurrences so that programmes can continue to operate. By validating (checking) any inputs, the exception mechanism also enables you to safeguard your code (API) from improper use.

For a moment, put yourself in the position of the transportation department. You must first be aware of the areas where drivers can encounter difficulties. The second step is to design and put up warning signs. Finally, you must offer alternate routes in case there are issues with the primary one.

The Java exception system functions similarly. In order to create "exception barriers" around potentially harmful code, we utilise try blocks throughout development. We also use catch blocks to provide "backup routes" and finally blocks to write code that should always execute.

We must at least alert the user to the danger if we are unable to offer a "backup route" or if we wish to give them the freedom to make their own decisions. Why? Just picture the outrage of a driver who arrives at a small bridge he cannot cross without noticing a single warning sign!

When writing our classes and methods in programming, we can't always anticipate how other programmers would utilise them. Because of this, it is impossible for us to predict exactly how to handle a unique scenario. Nevertheless, it's polite to inform others of the potential for extraordinary circumstances.


The throws keyword, which essentially declares that throwing exceptions is part of our method's usual behaviour in Java, enables us to achieve this. Anyone utilising the technique is therefore aware that they need to write code to handle exceptions.

Use the throws keyword if you don't intend to handle exceptions in your method but yet want to alert others that they might happen.

The method may throw an exception if specified criteria are satisfied, as indicated by this keyword in the method signature.

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Design of User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education