Jump to content

Exceptions: Difference between revisions

Line 23:
X.catch SillyError se
print(se.message)</lang>
 
=={{header|8086 Assembly}}==
{{works with|MS-DOS}}
 
An exception in assembly language is often little more than just a conditional branch. Most MS-DOS system calls return the carry flag set if an error occured, and the error code will be returned in <code>AX</code>. This lets you write your own exception handler that prints a relevant error message to the screen. You'll need to read the documentation to know what each error code means.
 
<lang asm>;syscall for creating a new file.
mov dx,offset filename
mov cx,0
mov ah,5Bh
int 21h
;if error occurs, will return carry set and error code in ax
;Error code 03h = path not found
;Error code 04h = Too many open files
;Error code 05h = Access denied
;Error code 50h = File already exists
 
jnc noError ;continue with program
 
cmp ax,03h
je PathNotFoundError ;unimplemented exception handler
 
cmp ax,04h
je TooManyOpenFilesError
 
cmp ax,05h
je AccessDeniedError
 
cmp ax,50h
je FileAlreadyExistsError
 
noError:</lang>
 
=={{header|Ada}}==
1,489

edits

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