libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
exception.c File Reference
#include "exception.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Data Structures

struct  C8_Exception
 Represents an exception. More...
 

Macros

#define C8_INVALID_INSTRUCTION_EXCEPTION_MESSAGE   "An invalid instruction exists in the input file."
 
#define C8_TOO_MANY_LABELS_EXCEPTION_MESSAGE   "Too many labels are defined in the input file."
 
#define C8_STACK_OVERFLOW_EXCEPTION_MESSAGE   "A stack overflow occurred during execution."
 
#define C8_INVALID_ARGUMENT_EXCEPTION_MESSAGE   "An invalid instruction argument was given."
 
#define C8_DUPLICATE_LABEL_EXCEPTION_MESSAGE   "A label was defined multiple times."
 
#define C8_INVALID_SYMBOL_EXCEPTION_MESSAGE   "An invalid symbol exists in the input file."
 
#define C8_MEMORY_ALLOCATION_EXCEPTION_MESSAGE   "Failed to allocate memory."
 
#define C8_UNKNOWN_EXCEPTION_MESSAGE   "An unknown error has occurred."
 
#define C8_TOO_MANY_SYMBOLS_EXCEPTION_MESSAGE   "Too many symbols exist in the input file."
 
#define C8_LOAD_FILE_FAILURE_EXCEPTION_MESSAGE   "Failed to load file."
 
#define C8_FILE_TOO_BIG_EXCEPTION_MESSAGE   "The given file is too big."
 
#define C8_INVALID_COLOR_PALETTE_EXCEPTION_MESSAGE   "Invalid color palette."
 
#define C8_INVALID_QUIRK_EXCEPTION_MESSAGE   "Invalid quirk."
 
#define C8_FAILED_GRAPHICS_INITIALIZATION_EXCEPTION_MESSAGE   "Failed to initialize graphics."
 
#define C8_INVALID_FONT_EXCEPTION_MESSAGE   "Invalid font."
 
#define C8_INVALID_CLOCK_SPEED_EXCEPTION_MESSAGE   "Clock speed cannot be less than 1."
 
#define C8_STACK_UNDERFLOW_EXCEPTION_MESSAGE   "Stack underflow occurred during execution."
 

Functions

void c8_handle_exception (C8_ExceptionCode code)
 Handles an exception by printing the corresponding error message to stderr.
 

Variables

const C8_Exception c8_exceptions []
 
char c8_exception [BUFSIZ]
 Message to print when calling c8_handle_exception with a non-zero code.
 

Detailed Description

Note
NOT EXPORTED

Stuff for handling exceptions.

Macro Definition Documentation

◆ C8_DUPLICATE_LABEL_EXCEPTION_MESSAGE

#define C8_DUPLICATE_LABEL_EXCEPTION_MESSAGE   "A label was defined multiple times."

◆ C8_FAILED_GRAPHICS_INITIALIZATION_EXCEPTION_MESSAGE

#define C8_FAILED_GRAPHICS_INITIALIZATION_EXCEPTION_MESSAGE   "Failed to initialize graphics."

◆ C8_FILE_TOO_BIG_EXCEPTION_MESSAGE

#define C8_FILE_TOO_BIG_EXCEPTION_MESSAGE   "The given file is too big."

◆ C8_INVALID_ARGUMENT_EXCEPTION_MESSAGE

#define C8_INVALID_ARGUMENT_EXCEPTION_MESSAGE   "An invalid instruction argument was given."

◆ C8_INVALID_CLOCK_SPEED_EXCEPTION_MESSAGE

#define C8_INVALID_CLOCK_SPEED_EXCEPTION_MESSAGE   "Clock speed cannot be less than 1."

◆ C8_INVALID_COLOR_PALETTE_EXCEPTION_MESSAGE

#define C8_INVALID_COLOR_PALETTE_EXCEPTION_MESSAGE   "Invalid color palette."

◆ C8_INVALID_FONT_EXCEPTION_MESSAGE

#define C8_INVALID_FONT_EXCEPTION_MESSAGE   "Invalid font."

◆ C8_INVALID_INSTRUCTION_EXCEPTION_MESSAGE

#define C8_INVALID_INSTRUCTION_EXCEPTION_MESSAGE   "An invalid instruction exists in the input file."

◆ C8_INVALID_QUIRK_EXCEPTION_MESSAGE

#define C8_INVALID_QUIRK_EXCEPTION_MESSAGE   "Invalid quirk."

◆ C8_INVALID_SYMBOL_EXCEPTION_MESSAGE

#define C8_INVALID_SYMBOL_EXCEPTION_MESSAGE   "An invalid symbol exists in the input file."

◆ C8_LOAD_FILE_FAILURE_EXCEPTION_MESSAGE

#define C8_LOAD_FILE_FAILURE_EXCEPTION_MESSAGE   "Failed to load file."

◆ C8_MEMORY_ALLOCATION_EXCEPTION_MESSAGE

#define C8_MEMORY_ALLOCATION_EXCEPTION_MESSAGE   "Failed to allocate memory."

◆ C8_STACK_OVERFLOW_EXCEPTION_MESSAGE

#define C8_STACK_OVERFLOW_EXCEPTION_MESSAGE   "A stack overflow occurred during execution."

◆ C8_STACK_UNDERFLOW_EXCEPTION_MESSAGE

#define C8_STACK_UNDERFLOW_EXCEPTION_MESSAGE   "Stack underflow occurred during execution."

◆ C8_TOO_MANY_LABELS_EXCEPTION_MESSAGE

#define C8_TOO_MANY_LABELS_EXCEPTION_MESSAGE   "Too many labels are defined in the input file."

◆ C8_TOO_MANY_SYMBOLS_EXCEPTION_MESSAGE

#define C8_TOO_MANY_SYMBOLS_EXCEPTION_MESSAGE   "Too many symbols exist in the input file."

◆ C8_UNKNOWN_EXCEPTION_MESSAGE

#define C8_UNKNOWN_EXCEPTION_MESSAGE   "An unknown error has occurred."

Function Documentation

◆ c8_handle_exception()

void c8_handle_exception ( C8_ExceptionCode  code)

Handles an exception by printing the corresponding error message to stderr.

Parameters
codeThe exception code.

Variable Documentation

◆ c8_exception

char c8_exception[BUFSIZ]

Message to print when calling c8_handle_exception with a non-zero code.

◆ c8_exceptions

const C8_Exception c8_exceptions[]
Initial value:
= {
{ C8_INVALID_INSTRUCTION_EXCEPTION, "An invalid instruction exists in the input file." },
{ C8_TOO_MANY_LABELS_EXCEPTION, "Too many labels are defined in the input file." },
{ C8_STACK_OVERFLOW_EXCEPTION, "A stack overflow occurred during execution." },
{ C8_INVALID_ARGUMENT_EXCEPTION, "An invalid instruction argument was given." },
{ C8_DUPLICATE_LABEL_EXCEPTION, "A label was defined multiple times." },
{ C8_INVALID_SYMBOL_EXCEPTION, "An invalid symbol exists in the input file." },
{ C8_MEMORY_ALLOCATION_EXCEPTION, "Failed to allocate memory." },
{ C8_UNKNOWN_EXCEPTION, "An unknown error has occurred." },
{ C8_TOO_MANY_SYMBOLS_EXCEPTION, "Too many symbols exist in the input file." },
{ C8_LOAD_FILE_FAILURE_EXCEPTION, "Failed to load file." },
{ C8_FILE_TOO_BIG_EXCEPTION, "The given file is too big." },
{ C8_INVALID_COLOR_PALETTE_EXCEPTION, "Invalid color palette." },
{ C8_INVALID_QUIRK_EXCEPTION, "Invalid quirk." },
"Failed to initialize graphics." },
{ C8_INVALID_FONT_EXCEPTION, "Invalid font." },
{ C8_INVALID_CLOCK_SPEED_EXCEPTION, "Clock speed cannot be less than 1." },
{ C8_STACK_UNDERFLOW_EXCEPTION, "Stack underflow occurred during execution." },
}
@ C8_INVALID_CLOCK_SPEED_EXCEPTION
Definition: exception.h:46
@ C8_UNKNOWN_EXCEPTION
Definition: exception.h:38
@ C8_INVALID_SYMBOL_EXCEPTION
Definition: exception.h:36
@ C8_INVALID_ARGUMENT_EXCEPTION
Definition: exception.h:34
@ C8_MEMORY_ALLOCATION_EXCEPTION
Definition: exception.h:37
@ C8_LOAD_FILE_FAILURE_EXCEPTION
Definition: exception.h:40
@ C8_TOO_MANY_LABELS_EXCEPTION
Definition: exception.h:32
@ C8_INVALID_FONT_EXCEPTION
Definition: exception.h:45
@ C8_STACK_OVERFLOW_EXCEPTION
Definition: exception.h:33
@ C8_FAILED_GRAPHICS_INITIALIZATION_EXCEPTION
Definition: exception.h:44
@ C8_INVALID_COLOR_PALETTE_EXCEPTION
Definition: exception.h:42
@ C8_TOO_MANY_SYMBOLS_EXCEPTION
Definition: exception.h:39
@ C8_STACK_UNDERFLOW_EXCEPTION
Definition: exception.h:47
@ C8_DUPLICATE_LABEL_EXCEPTION
Definition: exception.h:35
@ C8_FILE_TOO_BIG_EXCEPTION
Definition: exception.h:41
@ C8_INVALID_INSTRUCTION_EXCEPTION
Definition: exception.h:31
@ C8_INVALID_QUIRK_EXCEPTION
Definition: exception.h:43