4
Most read
Development with Go
- Manjitsing K. Valvi
Error Handling
● Unwanted or unexpected condition occurring in program is ERROR
● E.g. File creation error, DB connection error, out of bound memory access etc.
● Error handling in Golang is unconventional as compared to that of languages like
Javascript, Java and Python
● Golang represents errors using the built-in error interface type
type error interface {
Error() string
}
● Interface contains a single method Error() that returns an error message as a string
● The error is often returned as a second argument of the function, making use of multiple
value return
Error Handling
● Go does not have exceptions like many other programming languages
● Go uses “Defer, panic and recover" for error handling
● A defer statement is a mechanism used to defer a function by putting it into an
executed stack once the function that contains the defer statement has finished, either
normally by executing a return statement or abnormally panicking
● A panic statement signals Golang that your code cannot solve the current problem and it
therefore stops the normal execution flow of your code
● Panics can be recovered by calling the built-in recover function within a deferred
function in the function that is panicking. Recover will then end the current state of
panic and return the panic error value
References
● “The Go Programming Language ”,Alan A.A.Donovan,Brian W.Kernighan,Addison Wesley Publication

More Related Content

PDF
Features of go
PDF
Getting Started with PHP Extensions
PDF
Drupal 8 customized checkout system
PPT
Behavior Driven Development with Rails
PPT
JavaScript Comments and Conditionals
PDF
Hidden Dragons of CGO
PDF
Stockholm JAM September 2018
Features of go
Getting Started with PHP Extensions
Drupal 8 customized checkout system
Behavior Driven Development with Rails
JavaScript Comments and Conditionals
Hidden Dragons of CGO
Stockholm JAM September 2018

What's hot (20)

PPTX
Flutter Festivals GDSC ASEB | Introduction to Dart
PDF
A Shallow Survey of Alternative Languages on the JVM
PDF
Why should a Java programmer shifts towards Functional Programming Paradigm
PDF
Kotlin & arrow: the functional way
PPTX
Ruby in mule
PPTX
Groovy demo
KEY
Jsx language-notes
PDF
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
PDF
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
PDF
Livecode widget course
PDF
Kotlin & Arrow the functional way
PDF
蔡学镛 Rebol漫谈
PPTX
The Practice of Programming - Notation
PPTX
Boosting python web apps with protocol buffers & grpc
PDF
An Introduction to Bazel
PDF
Boosting individual feedback with AutoFeedback
PDF
Adopting language server for apache camel feedback from a java/Eclipse plugi...
PDF
Post-graduate course: Object technology: Implementation of object-oriented pr...
PPT
Javascript Intro 01
PDF
Groovy as a Dynamic Language
Flutter Festivals GDSC ASEB | Introduction to Dart
A Shallow Survey of Alternative Languages on the JVM
Why should a Java programmer shifts towards Functional Programming Paradigm
Kotlin & arrow: the functional way
Ruby in mule
Groovy demo
Jsx language-notes
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
Livecode widget course
Kotlin & Arrow the functional way
蔡学镛 Rebol漫谈
The Practice of Programming - Notation
Boosting python web apps with protocol buffers & grpc
An Introduction to Bazel
Boosting individual feedback with AutoFeedback
Adopting language server for apache camel feedback from a java/Eclipse plugi...
Post-graduate course: Object technology: Implementation of object-oriented pr...
Javascript Intro 01
Groovy as a Dynamic Language
Ad

Similar to Error handling (15)

PDF
Defer, Panic, Recover
PPTX
golang_getting_started.pptx
PPTX
The GO Language : From Beginners to Gophers
PPTX
Go Programming language, golang
PDF
PPT
Introduction to Go ProgrammingLanguage.ppt
PDF
Learning Go Programming 1st Edition Vladimir Vivien
PDF
Go for SysAdmins - LISA 2015
PPTX
PPTX
Golang introduction
PPTX
go language- haseeb.pptx
ODP
Introduction to Go for Java Developers
PPTX
Golang - Overview of Go (golang) Language
PDF
Pointers & functions
Defer, Panic, Recover
golang_getting_started.pptx
The GO Language : From Beginners to Gophers
Go Programming language, golang
Introduction to Go ProgrammingLanguage.ppt
Learning Go Programming 1st Edition Vladimir Vivien
Go for SysAdmins - LISA 2015
Golang introduction
go language- haseeb.pptx
Introduction to Go for Java Developers
Golang - Overview of Go (golang) Language
Pointers & functions
Ad

More from Manjitsing Valvi (15)

PDF
Composite types
PDF
Basic types
PDF
Basic constructs ii
PDF
Basic constructs i
PDF
Introduction to golang
PDF
Operators
PDF
PDF
Digital marketing marketing strategies for digital world
PDF
Digital marketing channels
PDF
Digital marketing techniques
PDF
Social media marketing & managing cybersocial campaign
PDF
Creating marketing effective online store
PDF
Social media marketing tech tools and optimization for search engines
PDF
Digital marketing managing cybersocial campaign
PDF
Social media marketing
Composite types
Basic types
Basic constructs ii
Basic constructs i
Introduction to golang
Operators
Digital marketing marketing strategies for digital world
Digital marketing channels
Digital marketing techniques
Social media marketing & managing cybersocial campaign
Creating marketing effective online store
Social media marketing tech tools and optimization for search engines
Digital marketing managing cybersocial campaign
Social media marketing

Recently uploaded (20)

PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PPTX
Management Information system : MIS-e-Business Systems.pptx
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PPTX
introduction to high performance computing
PPTX
CyberSecurity Mobile and Wireless Devices
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PDF
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
PDF
Design Guidelines and solutions for Plastics parts
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Visual Aids for Exploratory Data Analysis.pdf
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Exploratory_Data_Analysis_Fundamentals.pdf
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Fundamentals of Mechanical Engineering.pptx
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Management Information system : MIS-e-Business Systems.pptx
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
introduction to high performance computing
CyberSecurity Mobile and Wireless Devices
Categorization of Factors Affecting Classification Algorithms Selection
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
Design Guidelines and solutions for Plastics parts
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS

Error handling

  • 1. Development with Go - Manjitsing K. Valvi
  • 2. Error Handling ● Unwanted or unexpected condition occurring in program is ERROR ● E.g. File creation error, DB connection error, out of bound memory access etc. ● Error handling in Golang is unconventional as compared to that of languages like Javascript, Java and Python ● Golang represents errors using the built-in error interface type type error interface { Error() string } ● Interface contains a single method Error() that returns an error message as a string ● The error is often returned as a second argument of the function, making use of multiple value return
  • 3. Error Handling ● Go does not have exceptions like many other programming languages ● Go uses “Defer, panic and recover" for error handling ● A defer statement is a mechanism used to defer a function by putting it into an executed stack once the function that contains the defer statement has finished, either normally by executing a return statement or abnormally panicking ● A panic statement signals Golang that your code cannot solve the current problem and it therefore stops the normal execution flow of your code ● Panics can be recovered by calling the built-in recover function within a deferred function in the function that is panicking. Recover will then end the current state of panic and return the panic error value
  • 4. References ● “The Go Programming Language ”,Alan A.A.Donovan,Brian W.Kernighan,Addison Wesley Publication