repl.it
@MayankGupta5/

customError

Go

No description

fork
loading
Files
  • main.go
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import (  
    "errors"
    "fmt"
)

func calculateArea(radius int) (int, error) {  
    if radius < 0 {
        return 0, errors.New("Provide Positive Number")
    }
    return radius * radius, nil
}

func main() {
  areaValue, err := calculateArea(-1);
  if err != nil {
    fmt.Println("Error Encountered...")
    return
  } 
  
  fmt.Println(areaValue)
}