2022-04-10 08:22:58 +00:00
|
|
|
// Copyright 2022 Dietrich Epp.
|
|
|
|
// This file is part of SyncFiles. SyncFiles is licensed under the terms of the
|
|
|
|
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
2022-04-10 08:09:17 +00:00
|
|
|
#ifndef MACOS_ERROR_H
|
|
|
|
#define MACOS_ERROR_H
|
|
|
|
|
2022-11-16 23:19:05 +00:00
|
|
|
// Error codes, corresponding to messages in a STR# resource. This should be
|
|
|
|
// kept in sync with STR# rSTRS_Errors in resources.r.
|
2022-04-10 08:09:17 +00:00
|
|
|
typedef enum {
|
2022-11-18 01:38:03 +00:00
|
|
|
// An unknown error occurred.
|
2022-04-10 08:09:17 +00:00
|
|
|
kErrUnknown = 1,
|
2022-11-18 01:38:03 +00:00
|
|
|
// An internal error occurred.
|
2022-04-10 08:09:17 +00:00
|
|
|
kErrInternal,
|
2022-11-18 01:38:03 +00:00
|
|
|
// Out of memory.
|
2022-04-10 08:09:17 +00:00
|
|
|
kErrOutOfMemory,
|
2022-11-18 01:38:03 +00:00
|
|
|
// Could not save project "^1".
|
2022-04-10 08:09:17 +00:00
|
|
|
kErrCouldNotSaveProject,
|
|
|
|
} ErrorCode;
|
|
|
|
|
2022-11-18 01:38:03 +00:00
|
|
|
// ExitError shows an error dialog with the given error message, then quits the
|
|
|
|
// program.
|
2022-04-10 08:09:17 +00:00
|
|
|
void ExitError(ErrorCode errCode);
|
|
|
|
|
2022-11-18 01:38:03 +00:00
|
|
|
// ExitErrorOS shows an error dialog with the given error message and an OS
|
|
|
|
// error code, then quits the program.
|
2022-04-10 08:09:17 +00:00
|
|
|
void ExitErrorOS(ErrorCode errCode, short osErr);
|
|
|
|
|
2022-11-18 01:38:03 +00:00
|
|
|
// ExitMemError shows an out of memory error and quits the program.
|
2022-04-10 08:09:17 +00:00
|
|
|
void ExitMemError(void);
|
|
|
|
|
2022-11-18 01:38:03 +00:00
|
|
|
// ExitAssert shows an assertion error and quits the program. The message may be
|
|
|
|
// NULL.
|
2022-04-10 08:09:17 +00:00
|
|
|
void ExitAssert(const unsigned char *file, int line,
|
|
|
|
const unsigned char *message);
|
|
|
|
|
2022-11-18 01:38:03 +00:00
|
|
|
// EXIT_ASSERT shows an assertion error and quits the program. The message may
|
|
|
|
// be NULL.
|
2022-04-10 08:09:17 +00:00
|
|
|
#define EXIT_ASSERT(str) ExitAssert("\p" __FILE__, __LINE__, str)
|
|
|
|
|
2022-11-18 01:38:03 +00:00
|
|
|
// ASSERT checks that the given condition is true. Otherwise, it displays an
|
|
|
|
// error message and quits the program.
|
2022-04-10 08:09:17 +00:00
|
|
|
#define ASSERT(p) \
|
|
|
|
do { \
|
|
|
|
if (!(p)) \
|
|
|
|
ExitAssert("\p" __FILE__, __LINE__, "\p" #p); \
|
|
|
|
} while (0)
|
|
|
|
|
2022-11-18 01:38:03 +00:00
|
|
|
// An ErrorParams contains the parameters for displaying en error alert window.
|
|
|
|
// This structure should be zeroed before use, in case additional fields are
|
|
|
|
// added.
|
2022-04-10 08:09:17 +00:00
|
|
|
struct ErrorParams {
|
2022-11-18 01:38:03 +00:00
|
|
|
// The application error code. If this is zero, it will be treated as
|
|
|
|
// kErrInternal.
|
2022-04-10 08:09:17 +00:00
|
|
|
ErrorCode err;
|
2022-11-18 01:38:03 +00:00
|
|
|
|
|
|
|
// The OS error code. This is displayed at the end of the error message,
|
|
|
|
// unless it is zero.
|
2022-11-16 23:19:05 +00:00
|
|
|
short osErr;
|
2022-11-18 01:38:03 +00:00
|
|
|
|
|
|
|
// If the error messages contain any string substitutions like "^1", those
|
|
|
|
// substitutions are replaced with this string.
|
2022-04-10 08:09:17 +00:00
|
|
|
const unsigned char *strParam;
|
|
|
|
};
|
|
|
|
|
2022-11-18 01:38:03 +00:00
|
|
|
// ShowError shows an error alert window to the user.
|
2022-04-10 08:09:17 +00:00
|
|
|
void ShowError(const struct ErrorParams *p);
|
|
|
|
|
|
|
|
#endif
|