2 Copyright (C) 2001-2008, The Perl Foundation.
7 src/pmc/exception.pmc - Exception PMC
11 This is the exception base class.
13 For now, this class is based on C<ResziablePMCArray>. This will change when the
14 full PMC PDD is implemented.
16 An exception object has these attributes:
22 Textual representation of the exception.
26 The exception type, (see F<include/parrot/exceptions.h>, F<except_type.pasm>).
30 The severity of the exception, (see F<src/exceptions.h>,
31 F<except_severity.pasm>).
35 Additional data for the exception.
47 The C code file in which the exception was raised.
51 The line of C code on which the exception was raised.
55 The PASM/PIR/Perl file in which the exception was raised.
59 The line of PASM/PIR/Perl code on which the exception was raised.
63 Any information attached by the HL. This shouldn't start with an
64 underscore (that is reserved for Parrot's internal usage. These are
67 Note: currently, HLL information must be indexed by number. Slots 9 and 10
68 are available for the HLL - This is subject to change.
72 When an exception handler is called, the exception object is passed as
73 as the first argument, the message as the second argument of the call.
74 These arguments can be retrieved with the C<get_results> opcode.
80 #include "parrot/parrot.h"
82 /* This finds the index of an attribute in an object's attribute store and
83 * returns it. Returns -1 if the attribute does not exist. */
85 get_attrib_index(PARROT_INTERP, PMC *self, STRING *name)
87 if (!string_compare(interp, name, CONST_STRING(interp, "message")))
90 if (!string_compare(interp, name, CONST_STRING(interp, "type")))
93 if (!string_compare(interp, name, CONST_STRING(interp, "severity")))
96 if (!string_compare(interp, name, CONST_STRING(interp, "payload")))
112 pmclass Exception extends ResizablePMCArray need_ext {
118 Initializes the exception with default values.
126 /* pre-fill 11 slots with PMCNULL */
127 SELF.set_integer_native(11);
132 =item C<STRING *get_string_keyed(PMC *key)>
134 Returns the Parrot string value for C<*key>. The only current recognized
135 C<key> is "_message".
137 =item C<STRING *get_string()>
139 Return the exception message.
145 VTABLE STRING *get_string_keyed(PMC *key) {
146 STRING *s = key_string(INTERP, key);
148 if (!string_compare(INTERP, s, CONST_STRING(INTERP, "_message")))
149 return SELF.get_string_keyed_int(0);
154 VTABLE STRING *get_string() {
155 return SELF.get_string_keyed_int(0);
160 =item C<INTVAL get_integer_keyed(PMC *key)>
162 Returns the integer value for C<*key>.
168 VTABLE INTVAL get_integer_keyed(PMC *key) {
169 STRING *s = key_string(INTERP, key);
171 if (!string_compare(INTERP, s, CONST_STRING(INTERP, "_type")))
172 return SELF.get_integer_keyed_int(1);
174 if (!string_compare(INTERP, s, CONST_STRING(INTERP, "_severity")))
175 return SELF.get_integer_keyed_int(2);
182 =item C<PMC *get_pmc_keyed(PMC *key)>
184 Returns the PMC value for C<*key>.
190 VTABLE PMC *get_pmc_keyed(PMC *key) {
191 STRING *s = key_string(INTERP, key);
192 return SELF.getprop(s);
197 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
199 Returns the PMC value of the element at index C<key>, but ignores too
206 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
207 if (key <= -PMC_int_val(SELF))
215 =item C<void set_string_keyed(PMC *key, STRING *value)>
217 Sets the Parrot string value for C<*key>.
223 VTABLE void set_string_keyed(PMC *key, STRING *value) {
224 STRING *s = key_string(INTERP, key);
226 if (!string_compare(INTERP, s, CONST_STRING(INTERP, "_message")))
227 SELF.set_string_keyed_int(0, value);
232 =item C<void set_integer_keyed(PMC *key, INTVAL value) >
234 Sets the integer value for C<*key>.
240 VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
241 STRING *s = key_string(INTERP, key);
243 if (!string_compare(INTERP, s, CONST_STRING(INTERP, "_type")))
244 SELF.set_integer_keyed_int(1, value);
246 if (!string_compare(INTERP, s, CONST_STRING(INTERP, "_severity")))
247 SELF.set_integer_keyed_int(2, value);
252 =item C<void set_pmc_keyed(PMC *key, PMC *value)>
254 Sets the PMC value for C<*key>.
260 VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
261 STRING *s = key_string(INTERP, key);
262 SELF.setprop(s, value);
266 =item C<INTVAL is_equal(PMC *value)>
268 Compare the passed in Exception with SELF. Returns True if C<SELF> isa C<value>
273 VTABLE INTVAL is_equal(PMC *value) {
274 /* RT#46689 check parents */
275 if (value->vtable->base_type == enum_class_Exception
276 || VTABLE_isa(INTERP, value, CONST_STRING(INTERP, "Exception")))
284 =item C<get_attr_str>
286 Retrieve an attribute value for the exception object.
291 VTABLE PMC *get_attr_str(STRING *name) {
292 INTVAL index = get_attrib_index(interp, SELF, name);
294 /* If lookup failed, exception. */
296 real_exception(interp, NULL, ATTRIB_NOT_FOUND,
297 "No such attribute '%S'", name);
299 return SELF.get_pmc_keyed_int(index);
304 =item C<set_attr_str>
306 Set an attribute value for the exception object.
311 VTABLE void set_attr_str(STRING *name, PMC *value) {
312 INTVAL index = get_attrib_index(interp, SELF, name);
314 /* If lookup failed, exception. */
316 real_exception(interp, NULL, ATTRIB_NOT_FOUND,
317 "No such attribute '%S'", name);
319 SELF.set_pmc_keyed_int(index, value);
324 =item C<shift_*>, C<unshift_*>, C<pop_*>, C<push_*>
326 These methods are silently ignored.
331 VTABLE PMC *shift_pmc() {
332 /* fprintf(stderr, "don't do that then\n"); RT#46691 */
336 VTABLE FLOATVAL shift_float() {
337 (void) SELF.shift_pmc();
341 VTABLE INTVAL shift_integer() {
342 (void) SELF.shift_pmc();
346 VTABLE STRING *shift_string() {
347 (void) SELF.shift_pmc();
351 void unshift_pmc(PMC *value) {
352 /* fprintf(stderr, "don't do that then\n"); RT#46691 */
355 VTABLE void unshift_float(FLOATVAL value) {
356 SELF.unshift_pmc(NULL);
359 VTABLE void unshift_integer(INTVAL value) {
360 SELF.unshift_pmc(NULL);
363 VTABLE void unshift_string(STRING *value) {
364 SELF.unshift_pmc(NULL);
367 void push_pmc(PMC *value) {
368 /* fprintf(stderr, "don't do that then\n"); RT#46691 */
371 VTABLE void push_float(FLOATVAL value) {
372 SELF.push_pmc(PMCNULL);
375 VTABLE void push_integer(INTVAL value) {
376 SELF.push_pmc(PMCNULL);
379 VTABLE void push_string(STRING *value) {
380 SELF.push_pmc(PMCNULL);
383 VTABLE PMC *pop_pmc() {
384 /* fprintf(stderr, "don't do that then\n"); RT#46691 */
388 VTABLE FLOATVAL pop_float() {
389 (void) SELF.pop_pmc();
393 VTABLE INTVAL pop_integer() {
394 (void) SELF.pop_pmc();
398 VTABLE STRING *pop_string() {
399 (void) SELF.pop_pmc();
410 Initial revision by leo 2003.07.10.
418 * c-file-style: "parrot"
420 * vim: expandtab shiftwidth=4: