• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*****************************************************************************/
2 // Copyright 2006-2007 Adobe Systems Incorporated
3 // All Rights Reserved.
4 //
5 // NOTICE:  Adobe permits you to use, modify, and distribute this file in
6 // accordance with the terms of the Adobe license agreement accompanying it.
7 /*****************************************************************************/
8 
9 /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_exceptions.cpp#2 $ */
10 /* $DateTime: 2012/06/06 12:08:58 $ */
11 /* $Change: 833617 $ */
12 /* $Author: tknoll $ */
13 
14 /*****************************************************************************/
15 
16 #include "dng_exceptions.h"
17 
18 #include "dng_flags.h"
19 #include "dng_globals.h"
20 
21 /*****************************************************************************/
22 
23 #ifndef qDNGReportErrors
24 // assuming this isn't enable on Win, because it's using printf, but an app can redirect that to console
25 #define qDNGReportErrors ((qDNGDebug && qMacOS) || qDNGValidate)
26 #endif
27 
28 /*****************************************************************************/
29 
ReportWarning(const char * message,const char * sub_message)30 void ReportWarning (const char *message,
31 				    const char *sub_message)
32 	{
33 
34 
35 	#if qDNGReportErrors
36 
37 	if (sub_message)
38 		fprintf (stderr, "*** Warning: %s (%s) ***\n", message, sub_message);
39 	else
40 		fprintf (stderr, "*** Warning: %s ***\n", message);
41 
42 	#else
43 
44 	(void) message;
45 	(void) sub_message;
46 
47 	#endif
48 
49 	}
50 
51 /*****************************************************************************/
52 
ReportError(const char * message,const char * sub_message)53 void ReportError (const char *message,
54 				  const char *sub_message)
55 	{
56 
57 	#if qDNGReportErrors
58 
59 	if (sub_message)
60 		fprintf (stderr, "*** Error: %s (%s) ***\n", message, sub_message);
61 	else
62 		fprintf (stderr, "*** Error: %s ***\n", message);
63 
64 	#else
65 
66 	(void) message;
67 	(void) sub_message;
68 
69 	#endif
70 
71 	}
72 
73 /*****************************************************************************/
74 
Throw_dng_error(dng_error_code err,const char * message,const char * sub_message,bool silent)75 void Throw_dng_error (dng_error_code err,
76 					  const char *message,
77 					  const char *sub_message,
78 					  bool silent)
79 	{
80 
81 	#if qDNGReportErrors
82 
83 		{
84 
85 		if (!message)
86 			{
87 
88 			switch (err)
89 				{
90 
91 				case dng_error_none:
92 				case dng_error_silent:
93 				case dng_error_user_canceled:
94 					{
95 					break;
96 					}
97 
98 				case dng_error_not_yet_implemented:
99 					{
100 					message = "Not yet implemented";
101 					break;
102 					}
103 
104 				case dng_error_host_insufficient:
105 					{
106 					message = "Host insufficient";
107 					break;
108 					}
109 
110 				case dng_error_memory:
111 					{
112 					message = "Unable to allocate memory";
113 					break;
114 					}
115 
116 				case dng_error_bad_format:
117 					{
118 					message = "File format is invalid";
119 					break;
120 					}
121 
122 				case dng_error_matrix_math:
123 					{
124 					message = "Matrix math error";
125 					break;
126 					}
127 
128 				case dng_error_open_file:
129 					{
130 					message = "Unable to open file";
131 					break;
132 					}
133 
134 				case dng_error_read_file:
135 					{
136 					message = "File read error";
137 					break;
138 					}
139 
140 				case dng_error_write_file:
141 					{
142 					message = "File write error";
143 					break;
144 					}
145 
146 				case dng_error_end_of_file:
147 					{
148 					message = "Unexpected end-of-file";
149 					break;
150 					}
151 
152 				case dng_error_file_is_damaged:
153 					{
154 					message = "File is damaged";
155 					break;
156 					}
157 
158 				case dng_error_image_too_big_dng:
159 					{
160 					message = "Image is too big to save as DNG";
161 					break;
162 					}
163 
164 				case dng_error_image_too_big_tiff:
165 					{
166 					message = "Image is too big to save as TIFF";
167 					break;
168 					}
169 
170 				case dng_error_unsupported_dng:
171 					{
172 					message = "DNG version is unsupported";
173 					break;
174 					}
175 
176 				default:
177 					{
178 					message = "Unknown error";
179 					break;
180 					}
181 
182 				}
183 
184 			}
185 
186 		if (message && !silent)
187 			{
188 			ReportError (message, sub_message);
189 			}
190 
191 		}
192 
193 	#else
194 
195 	(void) message;
196 	(void) sub_message;
197 	(void) silent;
198 
199 	#endif
200 
201 	throw dng_exception (err);
202 
203 	}
204 
205 /*****************************************************************************/
206