Jump to content

Halt and catch fire: Difference between revisions

m (Corrected a sentence.)
Line 75:
{{out}}
<pre>Undefined subroutine &main::a called at line 1.</pre>
 
=={{header|Phix}}==
I normally and quite often just use this:
<!--<lang Phix>(phixonline)-->
<span style="color: #0000FF;">?</span><span style="color: #000000;">9</span><span style="color: #0000FF;">/</span><span style="color: #000000;">0</span>
<!--</lang>-->
The ? means print and/but obviously the 9/0 triggers a fatal error before it gets that far.
{{out}}
<pre>
C:\Program Files (x86)\Phix\test.exw:1
attempt to divide by 0
 
Global & Local Variables
 
--> see C:\Program Files (x86)\Phix\ex.err
Press Enter...
</pre>
Alternatives include crash("some message") which produces similar output, and abort(n) which is somewhat quieter with abort(0) meaning (immediately) terminate normally without an error. All of those can be caught by try/catch: should you want to get properly brutal and defeat any active exception handler you can/must resort to inline assembly:
<!--<lang Phix>(phixonline)-->
<span style="color: #008080;">try</span>
#ilASM{
[PE32]
push 1 -- uExitCode
call "kernel32","ExitProcess"
[PE64]
sub rsp,8*5
mov rcx,1 -- uExitCode
call "kernel32","ExitProcess"
[ELF32]
xor ebx, ebx
mov eax, 1 -- SYSCALL_EXIT
int 0x80
[ELF64]
mov rax,231 -- sys_exit_group(rdi=int error_code)
xor rdi,rdi
syscall
}
<span style="color: #008080;">catch</span> <span style="color: #000000;">e</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">e</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">try</span>
<!--</lang>-->
No output, the try/catch is just for show. ExitProcess/sys_exit are the only non-catchable things I know of, apart from a few other deliberates such as quitting the debugger, and aside from being technically difficult to catch it seems reasonable to classify them as direct actions rather than errors.
 
=={{header|Raku}}==
7,822

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.