Jump to content

Segmentation fault protection: Difference between revisions

(Added Wren)
Line 20:
 
The 6502 uses memory-mapping to interact with external hardware, and reading/writing a memory location you normally shouldn't because your array indexed out of bounds can cause issues with external hardware, and even on some systems can result in a [[wp:Killer_poke|killer poke]] which can damage certain machines such as the Commodore PET. Memory-mapped ports don't work like normal memory; unlike normal memory, even ''reading'' a memory-mapped port can affect its contents, or affect the contents of other ports that are related to that hardware. (This isn't a property of the 6502 itself, but of the hardware connected to it.)
 
=={{header|Phix}}==
Phix has extensive compilation and runtime error handling, including bounds checking, unassigned variables, invalid assignments, and more, as well as exception handling, and strives to always deliver clear human-readable and actually useful error messages along with the file name and line number where they occurred - of course within reason, as the following example shows messages triggered by inline assembly are inherently always going to be a bit more cryptic than the norm.
<!--<lang Phix>(phixonline)-->
<span style="color: #008080;">try</span>
#ilASM{ xor eax,eax
mov eax,[eax]
}
<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>-->
{{out}}
<pre>
{30,10043489,3,21,"-1","e01.exw",`C:\Program Files (x86)\Phix\`,"fatal exception [MEMORY VIOLATION] at #00994061"}
</pre>
You could, of course, like the non-caught errors do, make that a bit prettier, in fact here is what you get without try/catch:
<pre>
C:\Program Files (x86)\Phix\e01.exw:3
fatal exception [MEMORY VIOLATION] at #008A9042
 
Global & Local Variables
 
--> see C:\Program Files (x86)\Phix\ex.err
Press Enter...
</pre>
The generated ex.err contains a full callstack and itemises in painstaking detail all variables and their values at the point of failure.
 
=={{header|Wren}}==
7,818

edits

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