Skip to content

No error handling for Go #9

@ns-cweber

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions