The document discusses Java exception handling. It begins with defining what exceptions are and what happens when exceptions occur. It then covers benefits of Java's exception handling framework such as separating error handling code from regular code, propagating errors up the call stack, and grouping exception types into hierarchies. The document also discusses how to catch exceptions using try-catch blocks and the finally keyword. It covers rules for throwing exceptions and shows Java's built-in exception class hierarchy.
Exceptions in java contains info about checked unchecked exceptions also methods for handling them. it also contains info about keywords like throw throws catch finally etc.
Exceptions in java contains info about checked unchecked exceptions also methods for handling them. it also contains info about keywords like throw throws catch finally etc.
1. Basic Java class
class Ex1
{
public static void main(String args[])
{
int width;
int length;
int height;
width=5;
length=12;
height=3;
int v;
v=width*length*height;
System.out.println("Volume is :"+v);
}
}
Volume is :180
Effective Java - Chapter 3: Methods Common to All Objectsİbrahim Kürce
Although object is a concrete class, it is designed primarily for extension.
All of its nonfinal methods (equals, hashCode, toString, clone, and finalize) have explicit general contracts because they are designed to be overridden.
This chapter tells you when and how to override the nonfinal Object methods. The finalize method is omitted from this chapter because it was discussed in Item 7. While not an Object method, Comparable.compareTo is discussed in this chapter because it has a similar character.
ppt of class and methods in java,recursion in java,nested class,java,command line argument,method overloading,call by value,call by reference,constructor overloading core java ppt
Exceptions are a powerful mechanism for centralized processing of errors and exceptional situations. This mechanism replaces the procedure-oriented method of error handling in which each function returns a code indicating an error or a successful execution.
unit 4 msbte syallbus for sem 4 2024-2025AKSHAYBHABAD5
The Intel 8086 microprocessor, designed by Intel in the late 1970s, is an 8-bit/16-bit microprocessor and the first member of the x86 family of microprocessors1. Here’s a brief overview of its internal architecture:
Complex Instruction Set Computer (CISC) Architecture: The 8086 microprocessor is based on a CISC architecture, which supports a wide range of instructions, many of which can perform multiple operations in a single instruction1.
Bus Interface Unit (BIU): The BIU is responsible for fetching instructions from memory and decoding them, while also managing data transfer between the microprocessor and memory or I/O devices1.
Execution Unit (EU): The EU executes the instructions1.
Memory Segmentation: The 8086 microprocessor has a segmented memory architecture, which means that memory is divided into segments that are addressed using both a segment register and an offset1.
Registers: The 8086 microprocessor has a rich set of registers, including general-purpose registers, segment registers, and special registers
This is the material that I prepared for gathering best practices in exception handling that we aim to follow. I used the content stated in the references section.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
2. Topics
● What is an Exception?
● What happens when an Exception occurs?
● Benefits of Exception Handling framework
● Catching exceptions with try-catch
● Catching exceptions with finally
● Throwing exceptions
● Rules in exception handling
● Exception class hierarchy
● Checked exception and unchecked exception
● Creating your own exception class
● Assertions 2
4. What is an Exception?
● Exceptional event
● Error that occurs during runtime
● Cause normal program flow to be disrupted
● Examples
– Divide by zero errors
– Accessing the elements of an array beyond its range
– Invalid input
– Hard disk crash
– Opening a non-existent file
– Heap memory exhausted
4
5. Exception Example
1 class DivByZero {
2 public static void main(String args[]) {
3 System.out.println(3/0);
4 System.out.println(“Pls. print me.”);
5 }
6 }
5
6. Example: Default Exception
Handling
● Displays this error message
Exception in thread "main"
java.lang.ArithmeticException: / by zero
at DivByZero.main(DivByZero.java:3)
● Default exception handler
– Provided by Java runtime
– Prints out exception description
– Prints the stack trace
● Hierarchy of methods where the exception occurred
– Causes the program to terminate
6
8. What Happens When an Exception
Occurs?
● When an exception occurs within a method, the
method creates an exception object and hands it off
to the runtime system
– Creating an exception object and handing it to the
runtime system is called “throwing an exception”
– Exception object contains information about the error,
including its type and the state of the program when the
error occurred
8
9. What Happens When an Exception
Occurs?
●
The runtime system searches the call stack
for a method that contains an exception
handler
9
10. What Happens When an Exception
Occurs?
● When an appropriate handler is found, the runtime
system passes the exception to the handler
– An exception handler is considered appropriate if the
type of the exception object thrown matches the type that
can be handled by the handler
– The exception handler chosen is said to catch the
exception.
● If the runtime system exhaustively searches all the
methods on the call stack without finding an
appropriate exception handler, the runtime system
(and, consequently, the program) terminates and
uses the default exception handler
10
13. Benefits of Java Exception
Handling Framework
● Separating Error-Handling code from “regular”
business logic code
● Propagating errors up the call stack
● Grouping and differentiating error types
13
14. Separating Error Handling Code
from Regular Code
● In traditional programming, error detection,
reporting, and handling often lead to confusing
spaghetti code
● Consider pseudocode method here that reads an
entire file into memory
readFile {
open the file;
determine its size;
allocate that much memory;
read the file into memory;
close the file;
}
14
15. Traditional Programming: No
separation of error handling code
● In traditional programming, To handle such cases,
the readFile function must have more code to do
error detection, reporting, and handling.
errorCodeType readFile {
initialize errorCode = 0;
open the file;
if (theFileIsOpen) {
determine the length of the file;
if (gotTheFileLength) {
allocate that much memory;
if (gotEnoughMemory) {
read the file into memory;
if (readFailed) {
errorCode = -1;
}
} else {
errorCode = -2; 15
}
16. Traditional Programming: No
separation of error handling code
●
} else {
errorCode = -3;
}
close the file;
if (theFileDidntClose && errorCode == 0) {
errorCode = -4;
} else {
errorCode = errorCode and -4;
}
} else {
errorCode = -5;
}
return errorCode;
}
16
17. Separating Error Handling Code
from Regular Code
● Exceptions enable you to write the main flow of
your code and to deal with the exceptional cases
elsewhere
readFile {
try {
open the file;
determine its size;
allocate that much memory;
read the file into memory;
close the file;
} catch (fileOpenFailed) {
doSomething;
} catch (sizeDeterminationFailed) {
doSomething;
} catch (memoryAllocationFailed) {
doSomething;
} catch (readFailed) {
doSomething;
} catch (fileCloseFailed) {
doSomething;
17
}
}
18. Separating Error Handling Code
from Regular Code
● Note that exceptions don't spare you the effort of
doing the work of detecting, reporting, and handling
errors, but they do help you organize the work more
effectively.
18
19. Propagating Errors Up the Call Stack
● Suppose that the readFile method is the fourth method in a
series of nested method calls made by the main program:
method1 calls method2, which calls method3, which finally
calls readFile
● Suppose also that method1 is the only method interested in
the errors that might occur within readFile.
method1 {
call method2;
}
method2 {
call method3;
}
method3 {
call readFile;
} 19
20. Traditional Way of Propagating Errors
method1 { ●
Traditional error-
errorCodeType error;
error = call method2; notification techniques
if (error) force method2 and
doErrorProcessing;
else method3 to propagate
}
proceed; the error codes returned
by readFile up the call
errorCodeType method2 {
errorCodeType error;
stack until the error
error = call method3; codes finally reach
if (error)
return error; method1—the only
else method that is
proceed;
} interested in them.
errorCodeType method3 {
errorCodeType error;
error = call readFile;
if (error)
return error;
else 20
proceed;
21. Using Java Exception Handling
method1 {
try { ●
A method can duck any
call method2; exceptions thrown
} catch (exception e) { within it, thereby
doErrorProcessing; allowing a method
} farther up the call stack
} to catch it. Hence, only
the methods that care
method2 throws exception { about errors have to
call method3; worry about detecting
} errors
●
Any checked exceptions
method3 throws exception {
that can be thrown
call readFile;
within a method must
}
be specified in its
throws clause. 21
22. Grouping and Differentiating Error
Types
● Because all exceptions thrown within a program are
objects, the grouping or categorizing of exceptions
is a natural outcome of the class hierarchy
● An example of a group of related exception classes
in the Java platform are those defined in java.io —
IOException and its descendants
– IOException is the most general and represents any type
of error that can occur when performing I/O
– Its descendants represent more specific errors. For
example, FileNotFoundException means that a file could
not be located on disk.
22
23. Grouping and Differentiating Error
Types
● A method can write specific handlers that can
handle a very specific exception
● The FileNotFoundException class has no
descendants, so the following handler can handle
only one type of exception.
catch (FileNotFoundException e) {
...
}
23
24. Grouping and Differentiating Error
Types
● A method can catch an exception based on its
group or general type by specifying any of the
exception's superclasses in the catch statement.
For example, to catch all I/O exceptions, regardless
of their specific type, an exception handler specifies
an IOException argument.
// Catch all I/O exceptions, including
// FileNotFoundException, EOFException, and so on.
catch (IOException e) {
...
24
}
29. Catching Exceptions:
Nested try's
class NestedTryDemo {
public static void main(String args[]){
try {
int a = Integer.parseInt(args[0]);
try {
int b = Integer.parseInt(args[1]);
System.out.println(a/b);
} catch (ArithmeticException e) {
System.out.println(“Div by zero error!");
}
//continued...
29
34. Catching Exceptions:
The finally Keyword
● Syntax:
try {
<code to be monitored for exceptions>
} catch (<ExceptionType1> <ObjName>) {
<handler if ExceptionType1 occurs>
} ...
} finally {
<code to be executed before the try block ends>
}
● Contains the code for cleaning up after a try or a
catch
34
35. Catching Exceptions:
The finally Keyword
● Block of code is always executed despite of
different scenarios:
– Forced exit occurs using a return, a continue or a break
statement
– Normal completion
– Caught exception thrown
● Exception was thrown and caught in the method
– Uncaught exception thrown
● Exception thrown was not specified in any catch block in
the method
35
36. Catching Exceptions:
The finally Keyword
1 class FinallyDemo {
2 static void myMethod(int n) throws Exception{
3 try {
4 switch(n) {
5 case 1: System.out.println("1st case");
6 return;
7 case 3: System.out.println("3rd case");
8 throw new RuntimeException("3!");
9 case 4: System.out.println("4th case");
10 throw new Exception("4!");
11 case 2: System.out.println("2nd case");
12 }
13 //continued... 36
40. Throwing Exceptions:
The throw Keyword
● Java allows you to throw exceptions (generate
exceptions)
throw <exception object>;
● An exception you throw is an object
– You have to create an exception object in the same way
you create any other object
● Example:
throw new ArithmeticException(“testing...”);
40
43. Rules on Exceptions
● A method is required to either catch or list all
exceptions it might throw
– Except for Error or RuntimeException, or their
subclasses
● If a method may cause an exception to occur but
does not catch it, then it must say so using the
throws keyword
– Applies to checked exceptions only
● Syntax:
<type> <methodName> (<parameterList>)
throws <exceptionList> {
<methodBody>
43
}
46. The Error and Exception Classes
● Throwable class
– Root class of exception classes
– Immediate subclasses
● Error
● Exception
● Exception class
– Conditions that user programs can reasonably deal with
– Usually the result of some flaws in the user program
code
– Examples
● Division by zero error
● Array out-of-bounds error 46
47. The Error and Exception Classes
● Error class
– Used by the Java run-time system to handle errors
occurring in the run-time environment
– Generally beyond the control of user programs
– Examples
● Out of memory errors
● Hard disk crash
47
51. Checked and Unchecked
Exceptions
● Checked exception
– Java compiler checks if the program either catches or lists the
occurring checked exception
– If not, compiler error will occur
● Unchecked exceptions
– Not subject to compile-time checking for exception handling
– Built-in unchecked exception classes
● Error
● RuntimeException
● Their subclasses
– Handling all these exceptions may make the program cluttered
and may become a nuisance
51
53. Creating Your Own Exception
Class
● Steps to follow
– Create a class that extends the RuntimeException or the
Exception class
– Customize the class
● Members and constructors may be added to the class
● Example:
1 class HateStringExp extends RuntimeException {
2 /* some code */
3 }
53
54. How To Use Your Own Exceptions
1 class TestHateString {
2 public static void main(String args[]) {
3 String input = "invalid input";
4 try {
5 if (input.equals("invalid input")) {
6 throw new HateStringExp();
7 }
8 System.out.println("Accept string.");
9 } catch (HateStringExp e) {
10 System.out.println("Hate string!”);
11 }
12 }
54
13 }
56. What are Assertions?
● Allow the programmer to find out if an assumption
was met
– Example: month
● Extension of comments wherein the assert
statement informs the person reading the code that
a particular condition should always be satisfied
– Running the program informs you if assertions made are
true or not
– If an assertion is not true, an AssertionError is thrown
● User has the option to turn it off or on at runtime
56
57. Enabling or Disabling Assertions
● Program with assertions may not work properly if
used by clients not aware that assertions were
used in the code
● Compiling
– With assertion feature:
javac –source 1.4 MyProgram.java
– Without the assertion feature:
javac MyProgram.java
● Enabling assertions:
– Use the –enableassertions or –ea switch.
java –enableassertions MyProgram
57
58. Assert Syntax
● Two forms:
– Simpler form:
assert <expression1>;
where
● <expression1> is the condition asserted to be true
– Other form:
assert <expression1> : <expression2>;
where
● <expression1> is the condition asserted to be true
● <expression2> is some information helpful in diagnosing why the statement failed
58
59. Assert Syntax
1 class AgeAssert {
2 public static void main(String args[]) {
3 int age = Integer.parseInt(args[0]);
4 assert(age>0);
5 /* if age is valid (i.e., age>0) */
6 if (age >= 18) {
7 System.out.println(“You're an adult! =)”);
8 }
9 }
10 }
59