Source file src/runtime/testdata/testprog/panicprint.go

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import "sync"
     8  
     9  type MyBool bool
    10  type MyComplex128 complex128
    11  type MyComplex64 complex64
    12  type MyFloat32 float32
    13  type MyFloat64 float64
    14  type MyInt int
    15  type MyInt8 int8
    16  type MyInt16 int16
    17  type MyInt32 int32
    18  type MyInt64 int64
    19  type MyString string
    20  type MyUint uint
    21  type MyUint8 uint8
    22  type MyUint16 uint16
    23  type MyUint32 uint32
    24  type MyUint64 uint64
    25  type MyUintptr uintptr
    26  
    27  func panicCustomComplex64() {
    28  	panic(MyComplex64(0.11 + 3i))
    29  }
    30  
    31  func panicCustomComplex128() {
    32  	panic(MyComplex128(32.1 + 10i))
    33  }
    34  
    35  func panicCustomString() {
    36  	panic(MyString("Panic\nline two"))
    37  }
    38  
    39  func panicCustomBool() {
    40  	panic(MyBool(true))
    41  }
    42  
    43  func panicCustomInt() {
    44  	panic(MyInt(93))
    45  }
    46  
    47  func panicCustomInt8() {
    48  	panic(MyInt8(93))
    49  }
    50  
    51  func panicCustomInt16() {
    52  	panic(MyInt16(93))
    53  }
    54  
    55  func panicCustomInt32() {
    56  	panic(MyInt32(93))
    57  }
    58  
    59  func panicCustomInt64() {
    60  	panic(MyInt64(93))
    61  }
    62  
    63  func panicCustomUint() {
    64  	panic(MyUint(93))
    65  }
    66  
    67  func panicCustomUint8() {
    68  	panic(MyUint8(93))
    69  }
    70  
    71  func panicCustomUint16() {
    72  	panic(MyUint16(93))
    73  }
    74  
    75  func panicCustomUint32() {
    76  	panic(MyUint32(93))
    77  }
    78  
    79  func panicCustomUint64() {
    80  	panic(MyUint64(93))
    81  }
    82  
    83  func panicCustomUintptr() {
    84  	panic(MyUintptr(93))
    85  }
    86  
    87  func panicCustomFloat64() {
    88  	panic(MyFloat64(-93.70))
    89  }
    90  
    91  func panicCustomFloat32() {
    92  	panic(MyFloat32(-93.70))
    93  }
    94  
    95  func panicDeferFatal() {
    96  	var mu sync.Mutex
    97  	defer mu.Unlock()
    98  	var i *int
    99  	*i = 0
   100  }
   101  
   102  func panicDoublieDeferFatal() {
   103  	var mu sync.Mutex
   104  	defer mu.Unlock()
   105  	defer func() {
   106  		panic(recover())
   107  	}()
   108  	var i *int
   109  	*i = 0
   110  }
   111  
   112  func init() {
   113  	register("panicCustomComplex64", panicCustomComplex64)
   114  	register("panicCustomComplex128", panicCustomComplex128)
   115  	register("panicCustomBool", panicCustomBool)
   116  	register("panicCustomFloat32", panicCustomFloat32)
   117  	register("panicCustomFloat64", panicCustomFloat64)
   118  	register("panicCustomInt", panicCustomInt)
   119  	register("panicCustomInt8", panicCustomInt8)
   120  	register("panicCustomInt16", panicCustomInt16)
   121  	register("panicCustomInt32", panicCustomInt32)
   122  	register("panicCustomInt64", panicCustomInt64)
   123  	register("panicCustomString", panicCustomString)
   124  	register("panicCustomUint", panicCustomUint)
   125  	register("panicCustomUint8", panicCustomUint8)
   126  	register("panicCustomUint16", panicCustomUint16)
   127  	register("panicCustomUint32", panicCustomUint32)
   128  	register("panicCustomUint64", panicCustomUint64)
   129  	register("panicCustomUintptr", panicCustomUintptr)
   130  	register("panicDeferFatal", panicDeferFatal)
   131  	register("panicDoublieDeferFatal", panicDoublieDeferFatal)
   132  }
   133  

View as plain text