This document provides an overview of an exception handling design and refactoring class given by Teddy Chen. It discusses Teddy's background and experience in areas like Scrum, design patterns, and exception handling. The class covers basic exception handling concepts, the 4+1 view of exception handling, and establishing a central idea of staged robustness. It also discusses exception handling mechanisms in programming languages like Java.
A summary of clean code concepts and tips along with some examples and good practices.
These are the slides translated in English from my talk on Clean Code to my coworkers back then
We like the architecture of our applications to revolve around the business logic, not around technical details (and especially not around the database).
In my team at Sky Network Services we use the Clean Architecture and it has given us a great deal of benefits: the business logic is explicit, we are free to change our technical decisions, the app is easy to test, working on it is faster and scalable, it’s hard to do the wrong thing, and many more.
But it comes at a cost, of course. In this talk I’ll tell you the story of our experience with Clean Architecture and give you some tips to get the most out of it.
Example Project
https://github.com/mattia-battiston/clean-architecture-example
Downloads
Online: https://goo.gl/DTxftJ
PDF: https://goo.gl/ZAtdBN
Powerpoint: https://goo.gl/D54wdZ (but you need to install these fonts to see it properly: https://goo.gl/iH8SO5)
A summary of clean code concepts and tips along with some examples and good practices.
These are the slides translated in English from my talk on Clean Code to my coworkers back then
We like the architecture of our applications to revolve around the business logic, not around technical details (and especially not around the database).
In my team at Sky Network Services we use the Clean Architecture and it has given us a great deal of benefits: the business logic is explicit, we are free to change our technical decisions, the app is easy to test, working on it is faster and scalable, it’s hard to do the wrong thing, and many more.
But it comes at a cost, of course. In this talk I’ll tell you the story of our experience with Clean Architecture and give you some tips to get the most out of it.
Example Project
https://github.com/mattia-battiston/clean-architecture-example
Downloads
Online: https://goo.gl/DTxftJ
PDF: https://goo.gl/ZAtdBN
Powerpoint: https://goo.gl/D54wdZ (but you need to install these fonts to see it properly: https://goo.gl/iH8SO5)
Presentación para la charla sobre el libro de Robert C. Martin, Clean Code.
Esta presentación la impartí en CyLicon Valley, aquí tenéis el video con el audio de la charla => https://www.youtube.com/watch?v=1Fss1jBfc3g
(video of these slides available here http://fsharpforfunandprofit.com/fppatterns/)
In object-oriented development, we are all familiar with design patterns such as the Strategy pattern and Decorator pattern, and design principles such as SOLID.
The functional programming community has design patterns and principles as well.
This talk will provide an overview of some of these, and present some demonstrations of FP design in practice.
Slides from a talk about unit tests in Node.js. The talk was held as a part of an internal Node.js course in ironSource's offices in Tel-Aviv. On Wednesday, September 14th, 2016
Hamcrest is a library for creating matchers for usage in unit tests, mocks and UI validation. This talk gives a brief introduction to using and writing Hamcrest matchers.
The topics covered:
* Basic introduction to Hamcrest
* Using Matchers in assertions
* Using Matchers with Mockito
* Writing custom matchers
* Ad-hoc matchers
Clean Architecture helps you build applications that are Independent of Frameworks, UI, Database or any external agency. This talk will be an introduction to Clean Architecture principles and system design in Python. We will choose a sample application and walk through a simple use case of creating clean code.
What you will gain from this talk:
* Grow your application with confidence
* Build applications to be independent of infrastructure like Web Frameworks, Database etc.
* Avoid mixing of business logic across different layers of your application
* Test close to 100% of your core business logic
* Keep your tests fast and independent of infrastructure (DB, Web Layer etc.)
Clean Architecture Essentials - Stockholm Software CraftsmanshipIvan Paulovich
About the talk:
Software Architecture is not about picking frameworks then gluing the pieces together! Let's dig into a software implementation designed to support the use cases, we will learn how to make the use cases a standalone component and see how a good architecture allows major decisions to be deferred. We will discuss component coupling and cohesion during the development timeline. Is your application architecture a Web Application? Are your tests taking too long to run? You will learn how to make the delivery mechanism an irrelevant and testable detail.
About the speaker:
Ivan Paulovich is an Agile .NET developer that enjoy solutions based on use cases and decoupled from technology details. Active on GitHub he supports OSS about Domain-Driven Design, TDD, Event Sourcing, CQRS, SOLID and Microservices. Microsoft MVP Reconnect. Checkout @ivanpaulovich on GitHub.
Presentación para la charla sobre el libro de Robert C. Martin, Clean Code.
Esta presentación la impartí en CyLicon Valley, aquí tenéis el video con el audio de la charla => https://www.youtube.com/watch?v=1Fss1jBfc3g
(video of these slides available here http://fsharpforfunandprofit.com/fppatterns/)
In object-oriented development, we are all familiar with design patterns such as the Strategy pattern and Decorator pattern, and design principles such as SOLID.
The functional programming community has design patterns and principles as well.
This talk will provide an overview of some of these, and present some demonstrations of FP design in practice.
Slides from a talk about unit tests in Node.js. The talk was held as a part of an internal Node.js course in ironSource's offices in Tel-Aviv. On Wednesday, September 14th, 2016
Hamcrest is a library for creating matchers for usage in unit tests, mocks and UI validation. This talk gives a brief introduction to using and writing Hamcrest matchers.
The topics covered:
* Basic introduction to Hamcrest
* Using Matchers in assertions
* Using Matchers with Mockito
* Writing custom matchers
* Ad-hoc matchers
Clean Architecture helps you build applications that are Independent of Frameworks, UI, Database or any external agency. This talk will be an introduction to Clean Architecture principles and system design in Python. We will choose a sample application and walk through a simple use case of creating clean code.
What you will gain from this talk:
* Grow your application with confidence
* Build applications to be independent of infrastructure like Web Frameworks, Database etc.
* Avoid mixing of business logic across different layers of your application
* Test close to 100% of your core business logic
* Keep your tests fast and independent of infrastructure (DB, Web Layer etc.)
Clean Architecture Essentials - Stockholm Software CraftsmanshipIvan Paulovich
About the talk:
Software Architecture is not about picking frameworks then gluing the pieces together! Let's dig into a software implementation designed to support the use cases, we will learn how to make the use cases a standalone component and see how a good architecture allows major decisions to be deferred. We will discuss component coupling and cohesion during the development timeline. Is your application architecture a Web Application? Are your tests taking too long to run? You will learn how to make the delivery mechanism an irrelevant and testable detail.
About the speaker:
Ivan Paulovich is an Agile .NET developer that enjoy solutions based on use cases and decoupled from technology details. Active on GitHub he supports OSS about Domain-Driven Design, TDD, Event Sourcing, CQRS, SOLID and Microservices. Microsoft MVP Reconnect. Checkout @ivanpaulovich on GitHub.
Test-driven Development (TDD) is a powerful technique for combining software design, unit testing, and coding in a continuous process to increase reliability and produce better code design. Using the TDD approach, developers write programs in very short development cycles: first the developer writes a failing automated test case that defines a new function or improvement, then produces code to pass that test, and finally refactors the new code to acceptable standards. The developer repeats this process many times until the behavior is complete and fully tested. Rob Myers demonstrates the essential TDD techniques, including unit testing with the common xUnit family of open source development frameworks, refactoring as just-in-time design, plus Fake It, Triangulate, and Obvious Implementation. During this hands-on session, you’ll use exercises to practice the techniques. With many years of product development experience using TDD, Rob will address the questions that arise during your own relaxed exploration of test-driven development.
Session from NDC London 2013
Writing unit tests is hard, isn't it? you need an entire set of tools just to start. One of the crucial decisions when building this set is picking up a mocking framework.
But BEWARE! what you choose has the ability to make you or break you!
Come to the session and see Dror Helper, once a mocking framework developer, show the good and the bad of different mocking frameworks (free and commercial) and make them battle to the death!
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedJoão Pedro Martins
Improving on a previous version of this session delivered in Lisbon, this deck describes the real experiences in architecting and developing a large software project that took 3 years to go live. It was presented at a 3,5hr ITARC2015 workshop in Stockholm, Sweden.
It has been said that one should code as if the person maintaining the code is a violent psychopath who knows where you live. But why do we work with psychopaths? That question unfortunately cannot be answered in this presentation. However, we can shed some light on how to code for readability hopefully avoiding the problem altogether.
Readable code is about a lot more than producing beautiful code. In fact, it has nothing really to do with the beauty of the code and everything to do with the ability to quickly understand what the code does.
In this presentation we will discuss why readable code is so important. We will cover six commonly reoccurring patterns that made code hard to read, why they occur, and how they can easily be avoided:
* Deep Nesting
* Unnecessary Generalization
* Ambiguous Naming
* Hard to Follow Flow of Execution
* Code Style vs. Individualism
* Code Comments
These concepts may be applied to any programming language.
Documentation: https://izumi.7mind.io/latest/release/doc/distage/
Github: https://github.com/pshirshov/izumi-r2
Pavel Shirshov - DIStage: purely functional programming without sacrificing modularity with modern dependency injection for Scala
- Modularity and its importance
- DI-like mechanisms and their issues in Scala
- Why people think that "DI doesn't compose with functional programming", and why that's not true
- Designing a staged DI, for wiring at runtime, at compile-time, or mixed
- Staging programs for reliability, power and performance
- The pains of supporting rich Scala types (incl. How to emulate kind-polymorphism in Scala 2)
- Garbage collection in DI for better tests and deployments
Pavel's bio: Language-agnostic software engineer, coding for 18 years,
10 years of hands-on commercial engineering experience.
Led a cluster orchestration team at Yandex, "the Russian Google"; implemented an internal orchestration solution, "ISS" (Scala/Java/C++), managing 50K+ physical hosts across 6 datacenters.
Today, Pavel owns Irish R&D company Septimal Mind.
TDD is now mainstream but a lot people don't know or don't remember what is its purpose. TDD is about software design not testing or catching bug. TDD helps developers to shape and create software with "good" design, what is a "good" design is something that we will discuss in the topic.
Testing Experience - Evolution of Test Automation FrameworksŁukasz Morawski
Implementing automated tests is something that everybody wants to do. If you ask
any tester, test automation is their aim. And while it may be the golden target, very
few testers take pains to assess the required knowledge, under the illusion that a
programming language or expensive tool will suffice to cope with all problems likely
to arise. This is not true. Writing good automated tests is much harder than that,
requiring knowledge this article will make clear
Lessons Learned in a Continuously Developing Service-Oriented Architecturemdwheele
The goal of this presentation is to highlight the successes in applying modern development practices that tend to be regarded as “too much overhead” for small development teams. I was one of those nay-sayers. This presentation is a journey in moving an overburdened development team into a more efficient environment where regular progress is made and realistic expectations in timelines become possible. I plan to cover topics such as agile project management, application design strategies, version control, unit testing, and all the reasons why these globally common practices are well worth buy-in at a developer and managerial level. Given time constraint on presentation length, the depth of technical discussion will be relatively shallow. As I progress through the talk, I plan to use a recent development project for illustrative purposes. By not diving too deep, the discussion can instead focus more on proving that these processes do have real return on investment for developers and project managers alike.
PVS-Studio and static code analysis techniqueAndrey Karpov
What is «static code analysis»? It is a technique that allows, at the same time with unit-tests, dynamic code analysis, code review and others, to increase code quality, increase its reliability and decrease the development time.
軟體開發的設計模式(Design Patterns)起源自建築師Christopher Alexander在1970年代對於建築模式的研究,其代表著作有《Notes on the Synthesis of Form》(形式綜合論)、《The Timeless Way of Build》(建築的永恆之道)與《A Pattern Language》(建築模式語言)。
1987年Kent Beck和Ward Cunningham率先將模式應用於軟體介面設計,後續經由GoF的《Design Patterns》一書與PLoP研討會將其發揚光大。
已有超過數千個模式被發表,應用領域早已超越軟體設計,涵蓋需求、分析、架構、實作、測試、建構管理、持續整合、資料處理、敏捷開發、HCI/UI/UX、企業變革管理、教育乃至於日常生活等各種領域。
模式以特定格式撰寫,常見的格式有好幾種。不論其格式為何,大都具備六大基本元素:模式名稱(Pattern Name)、脈絡(Context)、問題(Problem)、作用力(Forces)、解法(Solution)、結果(Resulting Context)。了解這六大元素,便可掌握各種模式的核心要點。
本次C. C. Agile聚會,Teddy將跟著大家一起閱讀Daily Scrum這個常見的模式,以此為例說明模式的六大元素以及如何掌握閱讀模式的秘訣。
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024Neo4j
Neha Bajwa, Vice President of Product Marketing, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
UiPath Test Automation using UiPath Test Suite series, part 5DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 5. In this session, we will cover CI/CD with devops.
Topics covered:
CI/CD with in UiPath
End-to-end overview of CI/CD pipeline with Azure devops
Speaker:
Lyndsey Byblow, Test Suite Sales Engineer @ UiPath, Inc.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
Dr. Sean Tan, Head of Data Science, Changi Airport Group
Discover how Changi Airport Group (CAG) leverages graph technologies and generative AI to revolutionize their search capabilities. This session delves into the unique search needs of CAG’s diverse passengers and customers, showcasing how graph data structures enhance the accuracy and relevance of AI-generated search results, mitigating the risk of “hallucinations” and improving the overall customer journey.
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.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
17. 1. Representation
• 程式語言表達例外的方法
– Symbol
• strings or numbers
– Data object
• Used to hold error and failure information only.
• Raised by a language keyword.
– Full object
• Encapsulate signaling, propagation, and continuation
behaviors of exceptions in the class definition.
Copyright@2013 Teddysoft
18. 2. Definition
• 程式設計師如何定義一個例外
–Symbols
• new exceptions are defined as strings or
numbers.
–Data objects and full objects
• a class is used to define an exception.
Copyright@2013 Teddysoft
19. 3. Signaling
• 產生一個例外(的實例),並且將例外傳給
接收者的指令稱之為:
– throwing, signaling, raising, or triggering
• 例外產生方式有兩種:
– Synchronous exception
• A direct result of performing the instruction.
– Asynchronous exception
• Produced by the runtime environment upon encountering
an internal error or by stopping or suspending a thread.
Copyright@2013 Teddysoft
20. 4. Propagation
• If an exception is signaled and not coped
with locally, the exception can be propagated
to the caller of the signaling method.
• Exception propagation can be explicit or
implicit (or automatic).
– Explicit: a receiver must explicitly re-throw an
unhandled received exception for further propagation
– Implicit: an unhandled exception is automatically
propagated.
Copyright@2013 Teddysoft
21. 5. Resolution
• Exception resolution or handler binding is a process
of finding a suitable handler in the target, which is
resolved by static scoping at compiler-time, dynamic
invocation chain at runtime, or both.
• There are two methods to dynamically find a handler:
stack unwinding and stack cutting.
– Stack unwinding pops the stack frames to search for the
matching exception handler
– Stack cutting maintains a list of registered exception handlers
and looks up the list for a suitable exception handler.
Copyright@2013 Teddysoft
22. 6. Continuation
• An exception continuation or exception
model specifies the execution flow after
an exception handler returns its control.
–Termination model
–Retry model
–Resumption model
Copyright@2013 Teddysoft
23. 容易搞混且重要的觀念:Fault, Error,
Failure, Exception彼此的關係
fault error failure
exception
(1) design
(2) component
cause of failure a state may lead to
failure
service departs from
specification
represented by
Copyright@2013 Teddysoft
46. Declared Exception
Copyright@2013 Teddysoft
public void fetchRawBytesAndSetupMessage(DataInputStream aIS)
throws IOException, InvalidPacketException {
int length = aIS.readInt();
setMessageLength(length);
byte[] messageBody = new byte[length];
try {
aIS.readFully(messageBody);
} catch (EOFException e) {
throw new InvalidPacketException("Data Underflow");
}
setMessage(new String(messageBody));
}
47. Undeclared Exception (1/2)
Copyright@2013 Teddysoft
public Hamburg createHamburger(String type) {
Hamburg ham = null;
switch (type) {
case "pork":
ham = new SweetPorkHamburger();
break;
case "beef":
ham = new SweetBeefHamburger();
break;
default:
throw new RuntimeException
("Unsupported hamburger type:" +
type);
}
return ham;
}
48. Undeclared Exception (2/2)
Copyright@2013 Teddysoft
public void deposit(int value) {
if (value < 0 ) {
throw new IllegalArgumentException
("存款金額不得為負數.");
}
// doing normal deposit logic
}
49. 你在做例外處理還是容錯設計? (1/2)
Copyright@2013 Teddysoft
public void deposit(int value) throws
llegalArgumentException {
if (value < 0 ) {
throw new IllegalArgumentException
("存款金額不得為負數.");
}
// doing normal deposit logic
}
public void deposit(int value) {
if (value < 0 ) {
throw new IllegalArgumentException
("存款金額不得為負數.");
}
// doing normal deposit logic
}
D
UC
UCUD
50. 你在做例外處理還是容錯設計? (2/2)
public String execute(String cmd) throws
IOException,
NullPointerException,
IllegalArgumentException;
Copyright@2013 Teddysoft
UCD
CD
61. 不同的程式語言有不同的例外處理構件
• Java/C#
– try-catch-finally
• C++
– try-catch
– destructor
• Eiffel
– Exception handlers in Eiffel are attached at the method
level and all exceptions are caught by one handler.
61
Copyright@2013 Teddysoft
62. 重新思考try-catch-finally的責任與分工
• Try
– Implement requirements (can have alternatives)
– Prepare state recovery (e.g., make a check point)
• Catch
– Perform error and fault handling
– Report exceptional conditions
– Control retry flow
• Finally
– Release resources
– Drop check points if any
62
Copyright@2013 Teddysoft
71. Process View
• Waterfall VS. IID (iterative and
incremental development)
• 如何在IID流程中規劃例外處理?
– I will handle this exception when I have time.
Never happens!
Copyright@2013 Teddysoft
72. 以Scrum為例
• Story
– Normal scenarios
– Failure scenarios
• 這個sprint先做normal scenarios,下個
sprint再做failure scenarios
Copyright@2013 Teddysoft
敏捷開發讓例外處理變得好簡單啊! 才怪
81. Robustness levels of components
Element RL G0 RL G1 RL G2 RL G3
name undefined error-reporting state-recovery behavior-recovery
service
failing implicitly or
explicitly
failing explicitly failing explicitly delivered
state unknown or incorrect
unknown or
incorrect
correct correct
lifetime
terminated or
continued
terminated continued continued
how-
achieved
NA
(1) propagating all
unhandled
exceptions, and
(2) catching and
reporting them in
the main program
(1) error
recovery
and
(2) cleanup
(1) retry, and/or
(2) design
diversity, data
diversity, and
functional diversity
also known
as
NA failing-fast
weakly tolerant
and organized
panic
strongly tolerant,
self-repair, self-
healing, resilience,
and retry
Copyright@2013 Teddysoft
82. Upgrading and degrading
exception handling goals
82
fail-fast; keep
user informed
G0 G1 G2
restore state, clean up,
and keep programs alive
G3
attempt retries
all retries fail
state restoration
or cleanup fail
Copyright@2013 Teddysoft
83. Applicability for the robustness levels
83
RL Applicability
G1
In the early stage of system development
Prototyping
Applying an evolutionary development methodology
Time-to-market
G2
Outsourcing
Designing utility components used in different application domains
Behavior-recovery actions should be administered by the user
G3
Developing mission critical systems
Designing components having sufficient application context to
recover from behavioral failures, e.g., application controllers
Behavior-recovery actions are inappropriate to be administered by
the user
Copyright@2013 Teddysoft
88. What is Refactoring
• Improving the internal structure of a
software system without altering its
external behavior [fowler]
• Steps to perform refactoring:
– Identifying code smells
– Applying refactorings to remove the smells
– Verifying satisfaction
Copyright@2013 Teddysoft
89. Refactoring and EH Refactoring
89
Normal
Behavior
Exceptional
Behavior
Refactoring EH Refactoring
Behavior
Copyright@2013 Teddysoft
90. EH Smells, Refactorings, and RL
90
EH smell Refactoring RL
Return code Replace Error Code with Exception G1
Ignored checked
exception
Replace Ignored Checked Exception with
Unchecked Exception
G1
Unprotected main
program
Avoid Unexpected Termination with Big
Outer Try Block
G1
Dummy handler Replace Dummy Handler with Rethrow G1
Nested try block Replace Nested Try Block with Method G2
Careless Cleanup
Replace Careless Cleanup with Guaranteed
Cleanup
G2
Ignored checked
exception
Dummy handler
Introduce Checkpoint Class G2
Spare handler Introduce Resourceful Try Clause G3Copyright@2013 Teddysoft
91. Smell: Return Code
91
Copyright@2013 Teddysoft
public int withdraw(int amount) {
if (amount > this.balance)
return -1;
else {
this.balance = this.balance – amount;
return this.balance;
}
}
92. Refactoring: Replace Error Code with
Exception
92
Copyright@2013 Teddysoft
public int withdraw(int amount) throws
NotEnoughMoneyException {
if (amount > this.balance)
throw new NotEnoughMoneyException ();
this.balance = this.balance – amount;
}
93. Smell: Ignored Checked Exception
93
Copyright@2013 Teddysoft
public void writeFile(String fileName, String data) {
Writer writer = null;
try {
writer = new FileWriter(fileName);
// may throw IOException
writer.write(data); // may throw IOException
}
catch (IOException e) { // ignoring the exception }
finally { // code for cleanup }
}
94. Replace Ignored Checked Exception
with Unchecked Exception
public void writeFile(String fileName, String data) {
Writer writer = null;
try {
writer = new FileWriter(fileName); /* may throw an IOException */
writer.write(data); /* may throw an IOException */
}
catch (IOException e) {
/* ignoring the exception */
}
}
↓
public void writeFile(String fileName, String data) {
Writer writer = null;
try {
writer = new FileWriter(fileName); /* may throw an IOException */
writer.write(data); /* may throw an IOException */
}
catch (IOException e) {
throw new UnhandledException(e, “message”);
}
}
94
Copyright@2013 Teddysoft
95. Smell: Unprotected Main Program
95
Copyright@2013 Teddysoft
static public void main(String[] args) {
MyApp myapp = new MyApp();
myapp.start();
}
96. Avoid Unexpected Termination with
Big Outer Try Block
96
static public void main(String[] args) {
MyApp myapp = new MyApp();
myapp.start();
}
↓
static public void main(String[] args) {
try {
MyApp myapp = new MyApp();
myapp.start();
}
catch (Throwable e) {
/* displaying and/or logging the exception */
}
}
Copyright@2013 Teddysoft
106. Introduce Checkpoint Class
106
public void foo () throws FailureException {
try {
/* code that may change the state of the object */
}
catch (AnException e) {
throw new FailureException(e);
} finally {/* code for cleanup */}
}
↓
public void foo () throws FailureException {
Checkpoint cp = new Checkpoint (/* parameters */);
try {
cp. establish (); /* establish a checkpoint */
/* code that may change the state of the object */ }
catch (AnException e) {
cp.restore (); /* restore the checkpoint */
throw new FailureException(e); }
finally { cp.drop(); }
} Copyright@2013 Teddysoft