Marjan.nikolovski down the rabbit hole error handling examined-v01

Post on 16-Apr-2017

316 views 1 download

Transcript of Marjan.nikolovski down the rabbit hole error handling examined-v01

Ready

Marjan NikolovskiFather, Dev, CEO/Emit Knowledge

Down the rabbit holeError handling examined

try {

}

// Twitter: @m4rjann// Blog: emitknowledge.com/research-labs

Ready

Ready

Agenda

• Error theory;• Error types;• Handling error per type;• Responsible sides;• Error handling strategies;• Error handling for business logic;• Error handling for client;• Error handling for web applications;• Log analytics;

Ready

ERROR IS AN ANY INTERUPTION THAT STOPS THE SYSTEM TO EXECUTE A BUSINESS CONTEXT

Ready

A system must have a good strategy when it comes to error handling

Most of the code in a solution is trying to handle different types of errors and exceptions

It is easy to specify and write code to make the system operable. Hard times come when trying to predict what can go wrong

Ready

Bugs, issues we can’t predict nor control. Ex: Stackoverflow, Nullpointer...

Error types

using System;

class Program{ static void Main() {

User appUser = DomainServices.User.GetByUsername(@“marjann”);

Console.WriteLine(appUser.Email); }}

Ready

Error from invalid input.Ex: We expect integer value, the user enters some random characters...

Error types

using System;

class Program{ static void Main() {

var userIdInput = Console.ReadLine();int id = int.Parse(userIdInput);Console.WriteLine(id);

}}

Ready

Infrastructural problems.Ex: Missing write permissions on server, full disk, DB not available...

Error types

using System;

class Program{ static void Main() {

var user = UserRepository.GetByUsername(@”marjann”);Console.WriteLine(user.Email);

}}

Ready

Bugs are system problems that we can’t handle unless we apply a patch.

So what types of errors we can handle?

Invalid data entry is a system problem that we can handle proactively.

If we have infrastructural problems, the system should be able to notify the system administrators.

Ready

End clients who are using the system.

Responsible sides

System administrators.

Software developers.

Ready

Software developers.

Who should handle the bugs?

Ready

Global – architectural decision on system level.

Error handling strategies

Local-contextual – handling errors in a process/method/action.

Ready

КЛИЕНТ/КОРИСНИЧКИ ИНТЕРФЕЈС

БИЗНИС ЛОГИКА

ПОДАТОЧНО РЕПОЗИТОРИ

АПИ СЕРВИСИ

ЕКСТЕРНИ СЕРВИСИ

СПРАВУВАЊЕ СО ГРЕШКИ

ERROR HANDLING

Web/Mobile/Device REST API SERVICES

BUSINESS LOGIC

DATA REPOSITORY EXTERNAL SERVICES

Ready

Global perspective of the system.

GLOBAL STRATEGY

Centralized error handling.

We want detailed error instead of wrapped exception.

We want execution details.

We want unified error messages.

Ready

GLOBAL STRATEGY

Internally, a system should not hide the exceptions.Ex: User.IsExistingUsername(“marjann”) -> DbConnetionException != false

Externally, a system should always be transparent and should support unified error information when an error occurs.Ex: Invalid username, Username is not valid!?

Ready

Say hello to the local context.

What if we can retry?

Use local context as an exception to the rule!

We can’t predict and handle all of the errors, but we must keep the system alive.

Exception to the rule: If it does not work fake it!

Ready

Unification of errors, codes and groups.

Error handling for business logic

Information about an error(Error Info) against Exceptions.

Enrich an error with data for logging aspect.

Ready

Demo

Ready

Be transparent and show enough information to the end user.

Error handling for client

Ready

Demo

Ready

Error message localization.

Error handling for web applications

Transferring error information back to the app.

Ready

Demo

Ready

Who, What, How, Where, When?

Log analytics

PROM – tool for process mining.

We should be able to answer:- How our system is used?- Where our system perform slow?- Parameters of execution?- Patterns of execution?

Ready

Ready

catch(PPTException up){

}

Logger.Log(“QUESTIONS?”, up);throw up;