Added more exception handling after debugging ./examples/byte_for_demo.fun. (0.37.0)
This commit is contained in:
parent
ccd03d3bec
commit
26ddaf161e
12 changed files with 398 additions and 158 deletions
|
|
@ -1,5 +1,14 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*/
|
||||
|
||||
// Byte + for-loop demonstration
|
||||
|
||||
print("=== byte with hex literal and clamping ===")
|
||||
|
|
@ -32,6 +41,11 @@ print(typeof(x)) // -> "String"
|
|||
|
||||
/* Expected output:
|
||||
=== byte with hex literal and clamping ===
|
||||
OverflowError: value out of range for uint8
|
||||
*/
|
||||
|
||||
/* Expected output (OLD):
|
||||
=== byte with hex literal and clamping ===
|
||||
255
|
||||
255
|
||||
255
|
||||
|
|
|
|||
41
examples/byte_overflow_try_catch.fun
Executable file
41
examples/byte_overflow_try_catch.fun
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-10
|
||||
*/
|
||||
|
||||
// Demonstrate byte overflow with try/catch
|
||||
// Note: Runtime exceptions are not yet implemented; overflow emits an error and halts.
|
||||
// This example shows intended usage once exceptions are supported.
|
||||
|
||||
print("=== byte overflow with try/catch demo ===")
|
||||
try
|
||||
byte b = 0
|
||||
print("assign 255 -> ok")
|
||||
b = 255
|
||||
print(b)
|
||||
print("assign 256 -> should overflow and be caught")
|
||||
b = 256 // will trigger OverflowError: value out of range for uint8
|
||||
print("this line will not execute if overflow occurs")
|
||||
catch err
|
||||
print("caught error:")
|
||||
print(err)
|
||||
finally
|
||||
print("finally block executed")
|
||||
|
||||
/* Expected output:
|
||||
=== byte overflow with try/catch demo ===
|
||||
assign 255 -> ok
|
||||
255
|
||||
assign 256 -> should overflow and be caught
|
||||
caught error:
|
||||
OverflowError: value out of range for uint8
|
||||
finally block executed
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue