compiler
compiler copied to clipboard
✨ Add `panic` keyword to terminate a program.
Sometimes you just want to bail out of a program entirely because something has gone so wrong it is unrecoverable. This is often achieved by throwing or raising an Exception, with the understanding that the caller may catch that exception and recover in some other way.
With enums we already have a way to signal errors (by returning #error "..." for example) but we do not have a way to terminate the program prematurely. For that I think we should introduce a panic keyword which is in most respects synonymous with javascript's throw except for the fact that panics cannot be caught and handled.
Example:
pub fun toNumber x =
when x
is @Number n => #just n
is @String s => String.toNumber s
else => panic "Cannot coerce value to number."