Getting Started with Go: Error & File Handling

Go    |    Beginner
  • 12 videos | 1h 30m 19s
  • Includes Assessment
  • Earns a Badge
Rating 4.7 of 31 users Rating 4.7 of 31 users (31)
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 course
    Recognize error types and why error handling is such an important consideration
    Describe how error handling is implemented in go
    Use function return values to handle error conditions
    Recognize how to use package errors for managing errors
    Create and use custom error types
  • Use the defer statement, along with panic and recover built-in functions to manage exceptions
    Perform basic file operations in go including create, open, close, delete, truncate, rename, move, copy, and get file info
    Read an entire file into memory using package os
    Read a file line by line in go using package bufio
    Perform directory input/output operations in go
    Summarize the key concepts covered in this course

IN THIS COURSE

  • 1m 41s
    In 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 7s
    In 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
  • Locked
    3.  Error Handling in Go
    7m 20s
    In 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
  • Locked
    4.  Handling Errors in Go Programs
    6m 5s
    In 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
  • Locked
    5.  Working with Package errors in Go
    10m 6s
    In 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
  • Locked
    6.  Working with Custom Error Types in Go
    8m 16s
    In 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
  • Locked
    7.  Using Defer, Panic, and Recover to Manage Exceptions
    7m 17s
    In 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
  • Locked
    8.  Performing Basic File Operations in Go
    14m 54s
    In 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
  • Locked
    9.  Reading Files into Memory in Go
    6m 17s
    In 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
  • Locked
    10.  Reading Files Line by Line in Go
    7m 52s
    In 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
  • Locked
    11.  Performing Directory I/O Operations in Go
    12m 28s
    In 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
  • Locked
    12.  Course Summary
    57s
    In 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.

YOU MIGHT ALSO LIKE

Rating 4.5 of 15 users Rating 4.5 of 15 users (15)
Rating 4.5 of 201 users Rating 4.5 of 201 users (201)
Rating 4.6 of 18 users Rating 4.6 of 18 users (18)

PEOPLE WHO VIEWED THIS ALSO VIEWED THESE

Rating 4.5 of 22 users Rating 4.5 of 22 users (22)
Rating 4.6 of 13 users Rating 4.6 of 13 users (13)
Rating 4.5 of 107 users Rating 4.5 of 107 users (107)