Getting Started with Go: Error & File Handling
Go
| Beginner
- 12 videos | 1h 30m 19s
- Includes Assessment
- Earns a Badge
Go has a unique approach to error handling, treating errors as values that can be passed around and manipulated just like any other values. The language also provides several packages and built-ins in the standard library for working with file systems and performing I/O operations. In this course, you'll explore how errors are handled in Go using error values. You'll learn how to handle errors by importing and using package errors and work with custom error types. You'll examine how to implement Go's defer statement along with the built-in panic and recover functions to handle and recover from real-time errors. Finally, you'll learn about file input and output and how to perform basic I/O operations on files and directories.
WHAT YOU WILL LEARN
-
Discover the key concepts covered in this courseRecognize error types and why error handling is such an important considerationDescribe how error handling is implemented in goUse function return values to handle error conditionsRecognize how to use package errors for managing errorsCreate and use custom error types
-
Use the defer statement, along with panic and recover built-in functions to manage exceptionsPerform basic file operations in go including create, open, close, delete, truncate, rename, move, copy, and get file infoRead an entire file into memory using package osRead a file line by line in go using package bufioPerform directory input/output operations in goSummarize the key concepts covered in this course
IN THIS COURSE
-
1m 41sIn this video, you’ll learn more about this course and your instructor. In this course, you’ll learn how errors are handled in Go using error values. You'll handle errors by importing and using package errors and work with custom error types. You’ll also learn to implement Go's to first statement along with the built-in panic and recover functions to recover from real-time errors. Then you'll explore file input and output and perform basic i/o operations. FREE ACCESS
-
7m 7sIn this video, you’ll learn more about the rationale for error handling. An error is an event which occurs when an exception or an exceptional event happens. This means whenever something unexpected occurs and is unhandled in a normal flow of program execution. Errors are common in every programming language. Exceptions are errors, but they are recognizable errors that are known to occur. Exceptions alter the normal flow of execution in a program. FREE ACCESS
-
7m 20sIn this video, you’ll learn more about error handling in Go. In Go, errors are not like errors and exceptions in other programming languages. Errors in Go are simply values; normal Go values that are returned from functions just like any other value. They are represented with the built-in error type. This means that, like any other built-in type, you can store error values and variables and return them from functions. FREE ACCESS
-
6m 5sIn this video, you’ll watch a demo. You’ll learn about handling errors in Go programs. Error handling is an important feature of Go. Almost every function in Go has an error return type because Go's approach to error handling is to return errors explicitly as returned values. In fact, the idiomatic way to handle errors in Go is to test whether the returned error value is nil. If so, then no error has occurred. FREE ACCESS
-
10m 6sIn this video, you’ll watch a demo. In this demo, you'll work with Package errors. Package errors provide you with functions you can call to manipulate and manage errors. To get started, you’ll open your browser and navigate to golang.org/pkg/errors. This is the Package errors page and if you select Index, you’ll be presented with the functions you can use. Those are As, Is, New, and Unwrap. FREE ACCESS
-
8m 16sIn this video, you’ll watch a demo. You'll work with custom error types. There are various error conditions and the way they’re handled depends on several factors. Almost every function in Go returns an error value. You simply handle what's returned from the Go function. But if you're writing your own function and you want to handle a specific custom error, the new function from package errors allows you to do so. FREE ACCESS
-
7m 17sIn this video, you’ll watch a demo. In this demo, you’ll work with defer, panic, recover to handle exceptions in Go. To start, you’ll go to your local development machine. In the demo directory, you’ll see a file named main.go. On line 1 you have the package main declaration, then on line 3 you’ll see you have the import block. Then on lines 7 and 8, there are a couple of comments. FREE ACCESS
-
14m 54sIn this video, you’ll watch a demo. In this demo, you'll perform a number of basic file operations. To get started, you’ll open Visual Studio Code. In your DEMO folder you’ll see a sub folder called new, a file called del.txt, another one file.txt, your main program, main.go, myFile.txt, and src.txt. You’ll work with these directories and files as your work your way through this code. FREE ACCESS
-
6m 17sIn this video, you’ll watch a demo. In this demo, you'll read an entire file into memory using package os. To start, you’ll open Visual Studio Code. You’ll see a file named main.go in your DEMO directory; main.go has a package main statement on line 1 and an empty func main starting on line 3. Next, you’ll place the cursor on line 2, and press Enter several times to create space. FREE ACCESS
-
7m 52sIn this video, you’ll watch a demo. In this demo, you'll work with buffered I/O by reading text from a file line by line. Go to your DEMO directory to find a file named main.go. It has the package main statement on line 1 and a blank function main declaration starting on line 3. Place your cursor on line 2 and press Enter several times. With the cursor on line 3, specify your import statement. FREE ACCESS
-
12m 28sIn this video, you’ll watch a demo. In this demo, you'll perform directory I/O operations. You’ll open Visual Studio Code to your DEMO folder. You’ll see one file named main.go, and that's the file you’ll be working with. Onscreen, you’ll see Visual Studio Code's ability to expand and collapse regions of code. The import block is collapsed. If you click the right arrow, it expands the import block. FREE ACCESS
-
57sIn this video, you’ll summarize what you’ve learned in this course. In this course, you’ve learned how errors are handled and how file operations are performed in Go. You explored the importance of error handling and how it's implemented in Go. You also learned how to handle errors in Go programs and use the errors package. You explored using custom error types and the panic and recover functions and performed basic file operations in Go. FREE ACCESS
EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE
Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.
Digital badges are yours to keep, forever.