]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-errors.m
objc4-208.tar.gz
[apple/objc4.git] / runtime / objc-errors.m
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /*
25 * objc-errors.m
26 * Copyright 1988-1996, NeXT Software, Inc.
27 */
28
29 /*
30 NXLogObjcError was snarfed from "logErrorInc.c" in the kit.
31
32 Contains code for writing error messages to stderr or syslog.
33
34 This code is included in errors.m in the kit, and in pbs.c
35 so pbs can use it also.
36 */
37
38 #if defined(WIN32)
39 #import <winnt-pdo.h>
40 #import <windows.h>
41 #import <sys/types.h>
42 #import <sys/stat.h>
43 #import <io.h>
44 #define syslog(a, b, c) fprintf(stderr, b, c)
45 #else
46 #import <syslog.h>
47 #endif
48
49 #if defined(NeXT_PDO)
50 #if !defined(WIN32)
51 #include <syslog.h> // major head banging in attempt to find syslog
52 #import <stdarg.h>
53 #include <unistd.h> // close
54 #endif
55 #import <fcntl.h> // file open flags
56 #endif
57
58 #import "objc-private.h"
59
60 /*
61 * this routine handles errors that involve an object (or class).
62 */
63 volatile void __objc_error(id rcv, const char *fmt, ...)
64 {
65 va_list vp;
66
67 va_start(vp,fmt);
68 (*_error)(rcv, fmt, vp);
69 va_end(vp);
70 _objc_error (rcv, fmt, vp); /* In case (*_error)() returns. */
71 }
72
73 /*
74 * this routine is never called directly...it is only called indirectly
75 * through "_error", which can be overriden by an application. It is
76 * not declared static because it needs to be referenced in
77 * "objc-globaldata.m" (this file organization simplifies the shlib
78 * maintenance problem...oh well). It is, however, a "private extern".
79 */
80 volatile void _objc_error(id self, const char *fmt, va_list ap)
81 {
82 char bigBuffer[4*1024];
83
84 vsprintf (bigBuffer, fmt, ap);
85 _NXLogError ("objc: %s: %s", object_getClassName (self), bigBuffer);
86
87 #if defined(WIN32)
88 RaiseException(0xdead, EXCEPTION_NONCONTINUABLE, 0, NULL);
89 #else
90 abort(); /* generates a core file */
91 #endif
92 }
93
94 /*
95 * this routine handles severe runtime errors...like not being able
96 * to read the mach headers, allocate space, etc...very uncommon.
97 */
98 volatile void _objc_fatal(const char *msg)
99 {
100 _NXLogError("objc: %s\n", msg);
101 #if defined(WIN32)
102 RaiseException(0xdead, EXCEPTION_NONCONTINUABLE, 0, NULL);
103 #else
104 exit(1);
105 #endif
106 }
107
108 /*
109 * this routine handles soft runtime errors...like not being able
110 * add a category to a class (because it wasn't linked in).
111 */
112 void _objc_inform(const char *fmt, ...)
113 {
114 va_list ap;
115 char bigBuffer[4*1024];
116
117 va_start (ap,fmt);
118 vsprintf (bigBuffer, fmt, ap);
119 _NXLogError ("objc: %s", bigBuffer);
120 va_end (ap);
121 }
122