Write a Go program to implement a custom error using the errors.New() function.
MediumProblem Statement
Write a Go program to implement a custom error using the errors.New() function.
Sample Input
A predefined condition that triggers the error.
Sample Output
Error: value cannot be negative
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
package main
import ("errors" "fmt")
func checkValue(value int) error {
// Return an error if the value is less than 0
return nil
}
func main() {
// Check the value and handle the error
}
Input
A predefined condition that triggers the error.
Expected Output
Error: value cannot be negative