| 1 | #update=initial version |
| 2 | #file=main.zig |
| 3 | pub fn main() !u8 { |
| 4 | var a: u8 = undefined; |
| 5 | a = 255; |
| 6 | _ = a + 1; |
| 7 | return 1; |
| 8 | } |
| 9 | const no_panic = std.debug.no_panic; |
| 10 | pub const panic = struct { |
| 11 | pub const call = myPanic; |
| 12 | pub fn integerOverflow() noreturn { |
| 13 | @panic("integer overflow"); |
| 14 | } |
| 15 | pub const sentinelMismatch = no_panic.sentinelMismatch; |
| 16 | pub const unwrapError = no_panic.unwrapError; |
| 17 | pub const outOfBounds = no_panic.outOfBounds; |
| 18 | pub const startGreaterThanEnd = no_panic.startGreaterThanEnd; |
| 19 | pub const inactiveUnionField = no_panic.inactiveUnionField; |
| 20 | pub const sliceCastLenRemainder = no_panic.sliceCastLenRemainder; |
| 21 | pub const reachedUnreachable = no_panic.reachedUnreachable; |
| 22 | pub const unwrapNull = no_panic.unwrapNull; |
| 23 | pub const castToNull = no_panic.castToNull; |
| 24 | pub const incorrectAlignment = no_panic.incorrectAlignment; |
| 25 | pub const invalidErrorCode = no_panic.invalidErrorCode; |
| 26 | pub const unexpectedErrorCode = no_panic.unexpectedErrorCode; |
| 27 | pub const integerOutOfBounds = no_panic.integerOutOfBounds; |
| 28 | pub const shlOverflow = no_panic.shlOverflow; |
| 29 | pub const shrOverflow = no_panic.shrOverflow; |
| 30 | pub const divideByZero = no_panic.divideByZero; |
| 31 | pub const exactDivisionRemainder = no_panic.exactDivisionRemainder; |
| 32 | pub const integerPartOutOfBounds = no_panic.integerPartOutOfBounds; |
| 33 | pub const corruptSwitch = no_panic.corruptSwitch; |
| 34 | pub const shiftRhsTooBig = no_panic.shiftRhsTooBig; |
| 35 | pub const invalidEnumValue = no_panic.invalidEnumValue; |
| 36 | pub const forLenMismatch = no_panic.forLenMismatch; |
| 37 | pub const copyLenMismatch = no_panic.copyLenMismatch; |
| 38 | pub const memcpyAlias = no_panic.memcpyAlias; |
| 39 | pub const noreturnReturned = no_panic.noreturnReturned; |
| 40 | pub const loadUninstantiableType = no_panic.loadUninstantiableType; |
| 41 | }; |
| 42 | fn myPanic(msg: []const u8, _: ?usize) noreturn { |
| 43 | var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{}); |
| 44 | stdout_writer.interface.print("panic message: {s}\n", .{msg}) catch {}; |
| 45 | std.process.exit(0); |
| 46 | } |
| 47 | const std = @import("std"); |
| 48 | const io = std.Io.Threaded.global_single_threaded.io(); |
| 49 | #expect_stdout="panic message: integer overflow\n" |
| 50 | |
| 51 | #update=change the panic handler body |
| 52 | #file=main.zig |
| 53 | pub fn main() !u8 { |
| 54 | var a: u8 = undefined; |
| 55 | a = 255; |
| 56 | _ = a + 1; |
| 57 | return 1; |
| 58 | } |
| 59 | const no_panic = std.debug.no_panic; |
| 60 | pub const panic = struct { |
| 61 | pub const call = myPanic; |
| 62 | pub fn integerOverflow() noreturn { |
| 63 | @panic("integer overflow"); |
| 64 | } |
| 65 | pub const sentinelMismatch = no_panic.sentinelMismatch; |
| 66 | pub const unwrapError = no_panic.unwrapError; |
| 67 | pub const outOfBounds = no_panic.outOfBounds; |
| 68 | pub const startGreaterThanEnd = no_panic.startGreaterThanEnd; |
| 69 | pub const inactiveUnionField = no_panic.inactiveUnionField; |
| 70 | pub const sliceCastLenRemainder = no_panic.sliceCastLenRemainder; |
| 71 | pub const reachedUnreachable = no_panic.reachedUnreachable; |
| 72 | pub const unwrapNull = no_panic.unwrapNull; |
| 73 | pub const castToNull = no_panic.castToNull; |
| 74 | pub const incorrectAlignment = no_panic.incorrectAlignment; |
| 75 | pub const invalidErrorCode = no_panic.invalidErrorCode; |
| 76 | pub const unexpectedErrorCode = no_panic.unexpectedErrorCode; |
| 77 | pub const integerOutOfBounds = no_panic.integerOutOfBounds; |
| 78 | pub const shlOverflow = no_panic.shlOverflow; |
| 79 | pub const shrOverflow = no_panic.shrOverflow; |
| 80 | pub const divideByZero = no_panic.divideByZero; |
| 81 | pub const exactDivisionRemainder = no_panic.exactDivisionRemainder; |
| 82 | pub const integerPartOutOfBounds = no_panic.integerPartOutOfBounds; |
| 83 | pub const corruptSwitch = no_panic.corruptSwitch; |
| 84 | pub const shiftRhsTooBig = no_panic.shiftRhsTooBig; |
| 85 | pub const invalidEnumValue = no_panic.invalidEnumValue; |
| 86 | pub const forLenMismatch = no_panic.forLenMismatch; |
| 87 | pub const copyLenMismatch = no_panic.copyLenMismatch; |
| 88 | pub const memcpyAlias = no_panic.memcpyAlias; |
| 89 | pub const noreturnReturned = no_panic.noreturnReturned; |
| 90 | pub const loadUninstantiableType = no_panic.loadUninstantiableType; |
| 91 | }; |
| 92 | fn myPanic(msg: []const u8, _: ?usize) noreturn { |
| 93 | var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{}); |
| 94 | stdout_writer.interface.print("new panic message: {s}\n", .{msg}) catch {}; |
| 95 | std.process.exit(0); |
| 96 | } |
| 97 | const std = @import("std"); |
| 98 | const io = std.Io.Threaded.global_single_threaded.io(); |
| 99 | #expect_stdout="new panic message: integer overflow\n" |
| 100 | |
| 101 | #update=change the panic handler function value |
| 102 | #file=main.zig |
| 103 | pub fn main() !u8 { |
| 104 | var a: u8 = undefined; |
| 105 | a = 255; |
| 106 | _ = a + 1; |
| 107 | return 1; |
| 108 | } |
| 109 | const no_panic = std.debug.no_panic; |
| 110 | pub const panic = struct { |
| 111 | pub const call = myPanicNew; |
| 112 | pub fn integerOverflow() noreturn { |
| 113 | @panic("integer overflow"); |
| 114 | } |
| 115 | pub const sentinelMismatch = std.debug.no_panic.sentinelMismatch; |
| 116 | pub const unwrapError = std.debug.no_panic.unwrapError; |
| 117 | pub const outOfBounds = std.debug.no_panic.outOfBounds; |
| 118 | pub const startGreaterThanEnd = std.debug.no_panic.startGreaterThanEnd; |
| 119 | pub const inactiveUnionField = std.debug.no_panic.inactiveUnionField; |
| 120 | pub const sliceCastLenRemainder = no_panic.sliceCastLenRemainder; |
| 121 | pub const reachedUnreachable = no_panic.reachedUnreachable; |
| 122 | pub const unwrapNull = no_panic.unwrapNull; |
| 123 | pub const castToNull = no_panic.castToNull; |
| 124 | pub const incorrectAlignment = no_panic.incorrectAlignment; |
| 125 | pub const invalidErrorCode = no_panic.invalidErrorCode; |
| 126 | pub const unexpectedErrorCode = no_panic.unexpectedErrorCode; |
| 127 | pub const integerOutOfBounds = no_panic.integerOutOfBounds; |
| 128 | pub const shlOverflow = no_panic.shlOverflow; |
| 129 | pub const shrOverflow = no_panic.shrOverflow; |
| 130 | pub const divideByZero = no_panic.divideByZero; |
| 131 | pub const exactDivisionRemainder = no_panic.exactDivisionRemainder; |
| 132 | pub const integerPartOutOfBounds = no_panic.integerPartOutOfBounds; |
| 133 | pub const corruptSwitch = no_panic.corruptSwitch; |
| 134 | pub const shiftRhsTooBig = no_panic.shiftRhsTooBig; |
| 135 | pub const invalidEnumValue = no_panic.invalidEnumValue; |
| 136 | pub const forLenMismatch = no_panic.forLenMismatch; |
| 137 | pub const copyLenMismatch = no_panic.copyLenMismatch; |
| 138 | pub const memcpyAlias = no_panic.memcpyAlias; |
| 139 | pub const noreturnReturned = no_panic.noreturnReturned; |
| 140 | pub const loadUninstantiableType = no_panic.loadUninstantiableType; |
| 141 | }; |
| 142 | fn myPanicNew(msg: []const u8, _: ?usize) noreturn { |
| 143 | var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{}); |
| 144 | stdout_writer.interface.print("third panic message: {s}\n", .{msg}) catch {}; |
| 145 | std.process.exit(0); |
| 146 | } |
| 147 | const std = @import("std"); |
| 148 | const io = std.Io.Threaded.global_single_threaded.io(); |
| 149 | #expect_stdout="third panic message: integer overflow\n" |