summaryrefslogtreecommitdiff
path: root/gpr/source/lib/dng_sdk/dng_exceptions.cpp
blob: 6ca4ece5115565605be2621e025a176bd47f0212 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*****************************************************************************/
// Copyright 2006-2007 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in
// accordance with the terms of the Adobe license agreement accompanying it.
/*****************************************************************************/

/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_exceptions.cpp#2 $ */ 
/* $DateTime: 2012/06/06 12:08:58 $ */
/* $Change: 833617 $ */
/* $Author: tknoll $ */

/*****************************************************************************/

#include "dng_exceptions.h"

#include "dng_flags.h"
#include "dng_globals.h"

/*****************************************************************************/

#ifndef qDNGReportErrors
// assuming this isn't enable on Win, because it's using printf, but an app can redirect that to console
#define qDNGReportErrors ((qDNGDebug && qMacOS) || qDNGValidate)
#endif

/*****************************************************************************/

void ReportWarning (const char *message,
				    const char *sub_message)
	{
	
	
	#if qDNGReportErrors

	if (sub_message)
		fprintf (stderr, "*** Warning: %s (%s) ***\n", message, sub_message);
	else 
		fprintf (stderr, "*** Warning: %s ***\n", message);
	
	#else

	(void) message;
	(void) sub_message;
	
	#endif
	
	}

/*****************************************************************************/

void ReportError (const char *message,
				  const char *sub_message)
	{
	
	#if qDNGReportErrors

	if (sub_message)
		fprintf (stderr, "*** Error: %s (%s) ***\n", message, sub_message);
	else 
		fprintf (stderr, "*** Error: %s ***\n", message);
	
	#else

	(void) message;
	(void) sub_message;
	
	#endif
	
	}

/*****************************************************************************/

void Throw_dng_error (dng_error_code err,
					  const char *message,
					  const char *sub_message,
					  bool silent)
	{
	
	#if qDNGReportErrors
	
		{
		
		if (!message)
			{
		
			switch (err)
				{
				
				case dng_error_none:
				case dng_error_silent:
				case dng_error_user_canceled:
					{
					break;
					}
					
				case dng_error_not_yet_implemented:
					{
					message = "Not yet implemented";
					break;
					}
					
				case dng_error_host_insufficient:
					{
					message = "Host insufficient";
					break;
					}
				
				case dng_error_memory:
					{
					message = "Unable to allocate memory";
					break;
					}
					
				case dng_error_bad_format:
					{
					message = "File format is invalid";
					break;
					}
		
				case dng_error_matrix_math:
					{
					message = "Matrix math error";
					break;
					}
		
				case dng_error_open_file:
					{
					message = "Unable to open file";
					break;
					}
					
				case dng_error_read_file:
					{
					message = "File read error";
					break;
					}
					
				case dng_error_write_file:
					{
					message = "File write error";
					break;
					}
					
				case dng_error_end_of_file:
					{
					message = "Unexpected end-of-file";
					break;
					}
					
				case dng_error_file_is_damaged:
					{
					message = "File is damaged";
					break;
					}
					
				case dng_error_image_too_big_dng:
					{
					message = "Image is too big to save as DNG";
					break;
					}
					
				case dng_error_image_too_big_tiff:
					{
					message = "Image is too big to save as TIFF";
					break;
					}
					
				case dng_error_unsupported_dng:
					{
					message = "DNG version is unsupported";
					break;
					}
					
				default:
					{
					message = "Unknown error";
					break;
					}
					
				}
				
			}
			
		if (message && !silent)
			{
			ReportError (message, sub_message);
			}
		
		}
		
	#else
	
	(void) message;
	(void) sub_message;
	(void) silent;
	
	#endif
	
	throw dng_exception (err);
	
	}

/*****************************************************************************/