Skip to content

No error handling for Go #9

Description

@ns-cweber

Compiling the following program to Go produces no error handling logic:

import sys

print(int(sys.argv[1]))
package main

import (
	"strconv"
	"os"
	"fmt"
)

func main() {
	_int, _ := strconv.Atoi(os.Args[1]) // error handling missing
	fmt.Println(_int)
}

When we go run foo.go "not_an_int", the program prints 0 and exists successfully. When we python3 foo.py "not_an_int", we see:

Traceback (most recent call last):
  File "foo.py", line 3, in <module>
    print(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: 'not_an_int'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions