try

package module
v0.0.0-...-274a3f8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2019 License: MIT Imports: 0 Imported by: 0

README

try

A go package that offers a try/catch statement block.

Documentation

Here is a sample program making use of the try package. In this sample, variables in scope are accessed to demonstrate how this package interacts with your program.

package main

import (
	"github.com/thestrukture/try"
	"fmt"
	"errors"
)


func main(){

	count := 0

	try.Run(func(){
		count++
		count++

		// Will perform an error check, panic will
		// not be invoked if the interface passed is nil.
		try.Throw(errors.New("Crashed!"))

		fmt.Println(count);
	}).Catch(func(e interface{}){

		fmt.Println("Error : ", e)

	}).Finally(func(){
		fmt.Println("Done")
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Throw

func Throw(e interface{})

Throw abstracts writing error check statements. Throw will invoke panic when the parameter passed does not equal nil.

Types

type Error

type Error func(e interface{})

Error abstracts passing code blocks to handle errors generated

type Task

type Task func()

Task abstracts passing code blocks into the try/finally statement

type TryStatement

type TryStatement struct {
	// contains filtered or unexported fields
}

TryStatement is the type returned on execution of package function Try.. This enables chaining functions that compose the try/catch/finally statement.

func Run

func Run(t Task) TryStatement

Run initializes the try statement. The function passed is stored, to be ran later.

func (TryStatement) Catch

func (t TryStatement) Catch(e Error) TryStatement

Catch stores the error handler code block to the Try Statement.

func (TryStatement) Finally

func (t TryStatement) Finally(task Task)

Finally executes the statement and recovers from any panics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL