-// $G $D/$F.go && $L $F.$A && ./$A.out
+// run
-// Copyright 2010 The Go Authors. All rights reserved.
+// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test of recover for run-time errors.
// TODO(rsc):
-// integer divide by zero?
// null pointer accesses
package main
-import (
- "os"
- "strings"
- "syscall"
-)
+import "strings"
var x = make([]byte, 10)
if v == nil {
panic("expected panic")
}
- if e := v.(os.Error).String(); strings.Index(e, s) < 0 {
+ if e := v.(error).Error(); strings.Index(e, s) < 0 {
panic("want: " + s + "; have: " + e)
}
}
func test4() {
defer mustRecover("interface")
var x interface{} = 1
- println(x.(float))
+ println(x.(float32))
}
type T struct {
a, b int
+ c []int
}
func test5() {
}
func test6() {
- defer mustRecover("unhashable")
+ defer mustRecover("unhashable type main.T")
var x T
var z interface{} = x
m := make(map[interface{}]int)
}
func test7() {
- if syscall.ARCH == "arm" || syscall.OS == "nacl" {
- // ARM doesn't have integer divide trap yet
- return
- }
defer mustRecover("divide by zero")
var x, y int
println(x / y)