Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

error.c
Go to the documentation of this file.
1 /**********************************************************************
2
3 error.c -
4
5 $Author: nagachika $
6 created at: Mon Aug 9 16:11:34 JST 1993
7
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
9
10 **********************************************************************/
11
12 #include "ruby/ruby.h"
13 #include "ruby/st.h"
14 #include "ruby/encoding.h"
15 #include "internal.h"
16 #include "vm_core.h"
17
18 #include <stdio.h>
19 #include <stdarg.h>
20 #ifdef HAVE_STDLIB_H
21 #include <stdlib.h>
22 #endif
23 #include <errno.h>
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27
28 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
29
30 #ifndef EXIT_SUCCESS
31 #define EXIT_SUCCESS 0
32 #endif
33
34 #ifndef WIFEXITED
35 #define WIFEXITED(status) 1
36 #endif
37
38 #ifndef WEXITSTATUS
39 #define WEXITSTATUS(status) (status)
40 #endif
41
42 extern const char ruby_description[];
43
44 #define REPORTBUG_MSG \
45 "[NOTE]\n" \
46 "You may have encountered a bug in the Ruby interpreter" \
47 " or extension libraries.\n" \
48 "Bug reports are welcome.\n" \
49 "For details: http://www.ruby-lang.org/bugreport.html\n\n" \
50
51 static const char *
52 rb_strerrno(int err)
53 {
54 #define defined_error(name, num) if (err == (num)) return (name);
55 #define undefined_error(name)
56 #include "known_errors.inc"
57 #undef defined_error
58 #undef undefined_error
59 return NULL;
60 }
61
62 static int
63 err_position_0(char *buf, long len, const char *file, int line)
64 {
65 if (!file) {
66 return 0;
67 }
68 else if (line == 0) {
69 return snprintf(buf, len, "%s: ", file);
70 }
71 else {
72 return snprintf(buf, len, "%s:%d: ", file, line);
73 }
74 }
75
76 static VALUE
77 compile_snprintf(rb_encoding *enc, const char *pre, const char *file, int line, const char *fmt, va_list args)
78 {
79 VALUE str = rb_enc_str_new(0, 0, enc);
80
81 if (file) {
82 rb_str_cat2(str, file);
83 if (line) rb_str_catf(str, ":%d", line);
84 rb_str_cat2(str, ": ");
85 }
86 if (pre) rb_str_cat2(str, pre);
87 rb_str_vcatf(str, fmt, args);
88 return str;
89 }
90
91 static void
92 compile_err_append(VALUE mesg)
93 {
94 rb_thread_t *th = GET_THREAD();
95 VALUE err = th->errinfo;
96 rb_block_t *prev_base_block = th->base_block;
97 th->base_block = 0;
98 /* base_block should be zero while normal Ruby execution */
99 /* after this line, any Ruby code *can* run */
100
101 if (th->mild_compile_error) {
102 if (RTEST(err)) {
103 VALUE str = rb_obj_as_string(err);
104
105 rb_str_cat2(str, "\n");
106 rb_str_append(str, mesg);
107 mesg = str;
108 }
109 err = rb_exc_new3(rb_eSyntaxError, mesg);
110 th->errinfo = err;
111 }
112 else {
113 if (!RTEST(err)) {
114 err = rb_exc_new2(rb_eSyntaxError, "compile error");
115 th->errinfo = err;
116 }
117 rb_str_cat2(mesg, "\n");
118 rb_write_error_str(mesg);
119 }
120
121 /* returned to the parser world */
122 th->base_block = prev_base_block;
123 }
124
125 void
126 rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt, ...)
127 {
128 va_list args;
129 VALUE str;
130
131 va_start(args, fmt);
132 str = compile_snprintf(enc, NULL, file, line, fmt, args);
133 va_end(args);
134 compile_err_append(str);
135 }
136
137 void
138 rb_compile_error(const char *file, int line, const char *fmt, ...)
139 {
140 va_list args;
141 VALUE str;
142
143 va_start(args, fmt);
144 str = compile_snprintf(NULL, NULL, file, line, fmt, args);
145 va_end(args);
146 compile_err_append(str);
147 }
148
149 void
150 rb_compile_error_append(const char *fmt, ...)
151 {
152 va_list args;
153 VALUE str;
154
155 va_start(args, fmt);
156 str = rb_vsprintf(fmt, args);
157 va_end(args);
158 compile_err_append(str);
159 }
160
161 static void
162 compile_warn_print(const char *file, int line, const char *fmt, va_list args)
163 {
164 VALUE str;
165
166 str = compile_snprintf(NULL, "warning: ", file, line, fmt, args);
167 rb_str_cat2(str, "\n");
168 rb_write_error_str(str);
169 }
170
171 void
172 rb_compile_warn(const char *file, int line, const char *fmt, ...)
173 {
174 va_list args;
175
176 if (NIL_P(ruby_verbose)) return;
177
178 va_start(args, fmt);
179 compile_warn_print(file, line, fmt, args);
180 va_end(args);
181 }
182
183 /* rb_compile_warning() reports only in verbose mode */
184 void
185 rb_compile_warning(const char *file, int line, const char *fmt, ...)
186 {
187 va_list args;
188
189 if (!RTEST(ruby_verbose)) return;
190
191 va_start(args, fmt);
192 compile_warn_print(file, line, fmt, args);
193 va_end(args);
194 }
195
196 static void
197 warn_print(const char *fmt, va_list args)
198 {
199 VALUE str = rb_str_new(0, 0);
200 VALUE file = rb_sourcefilename();
201
202 if (!NIL_P(file)) {
203 int line = rb_sourceline();
204 str = rb_str_append(str, file);
205 if (line) rb_str_catf(str, ":%d", line);
206 rb_str_cat2(str, ": ");
207 }
208
209 rb_str_cat2(str, "warning: ");
210 rb_str_vcatf(str, fmt, args);
211 rb_str_cat2(str, "\n");
212 rb_write_error_str(str);
213 }
214
215 void
216 rb_warn(const char *fmt, ...)
217 {
218 va_list args;
219
220 if (NIL_P(ruby_verbose)) return;
221
222 va_start(args, fmt);
223 warn_print(fmt, args);
224 va_end(args);
225 }
226
227 /* rb_warning() reports only in verbose mode */
228 void
229 rb_warning(const char *fmt, ...)
230 {
231 va_list args;
232
233 if (!RTEST(ruby_verbose)) return;
234
235 va_start(args, fmt);
236 warn_print(fmt, args);
237 va_end(args);
238 }
239
240 /*
241 * call-seq:
242 * warn(msg, ...) -> nil
243 *
244 * Displays each of the given messages followed by a record separator on
245 * STDERR unless warnings have been disabled (for example with the
246 * <code>-W0</code> flag).
247 *
248 * warn("warning 1", "warning 2")
249 *
250 * <em>produces:</em>
251 *
252 * warning 1
253 * warning 2
254 */
255
256 static VALUE
257 rb_warn_m(int argc, VALUE *argv, VALUE exc)
258 {
259 if (!NIL_P(ruby_verbose) && argc > 0) {
260 rb_io_puts(argc, argv, rb_stderr);
261 }
262 return Qnil;
263 }
264
265 static void
266 report_bug(const char *file, int line, const char *fmt, va_list args)
267 {
268 /* SIGSEGV handler might have a very small stack. Thus we need to use it carefully. */
269 char buf[256];
270 FILE *out = stderr;
271 int len = err_position_0(buf, 256, file, line);
272
273 if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
274 (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
275
276 fputs("[BUG] ", out);
277 vsnprintf(buf, 256, fmt, args);
278 fputs(buf, out);
279 snprintf(buf, 256, "\n%s\n\n", ruby_description);
280 fputs(buf, out);
281
282
283 rb_vm_bugreport();
284
285 fprintf(out, REPORTBUG_MSG);
286 }
287 }
288
289 void
290 rb_bug(const char *fmt, ...)
291 {
292 va_list args;
293 const char *file = NULL;
294 int line = 0;
295
296 if (GET_THREAD()) {
297 file = rb_sourcefile();
298 line = rb_sourceline();
299 }
300
301 va_start(args, fmt);
302 report_bug(file, line, fmt, args);
303 va_end(args);
304
305 #if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
306 _set_abort_behavior( 0, _CALL_REPORTFAULT);
307 #endif
308
309 abort();
310 }
311
312 void
313 rb_bug_errno(const char *mesg, int errno_arg)
314 {
315 if (errno_arg == 0)
316 rb_bug("%s: errno == 0 (NOERROR)", mesg);
317 else {
318 const char *errno_str = rb_strerrno(errno_arg);
319 if (errno_str)
320 rb_bug("%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
321 else
322 rb_bug("%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
323 }
324 }
325
326 /*
327 * this is safe to call inside signal handler and timer thread
328 * (which isn't a Ruby Thread object)
329 */
330 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
331 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
332
333 void
334 rb_async_bug_errno(const char *mesg, int errno_arg)
335 {
336 WRITE_CONST(2, "[ASYNC BUG] ");
337 write_or_abort(2, mesg, strlen(mesg));
338 WRITE_CONST(2, "\n");
339
340 if (errno_arg == 0) {
341 WRITE_CONST(2, "errno == 0 (NOERROR)\n");
342 }
343 else {
344 const char *errno_str = rb_strerrno(errno_arg);
345
346 if (!errno_str)
347 errno_str = "undefined errno";
348 write_or_abort(2, errno_str, strlen(errno_str));
349 }
350 WRITE_CONST(2, "\n\n");
351 write_or_abort(2, ruby_description, strlen(ruby_description));
352 WRITE_CONST(2, "\n\n");
353 WRITE_CONST(2, REPORTBUG_MSG);
354 abort();
355 }
356
357 void
358 rb_compile_bug(const char *file, int line, const char *fmt, ...)
359 {
360 va_list args;
361
362 va_start(args, fmt);
363 report_bug(file, line, fmt, args);
364 va_end(args);
365
366 abort();
367 }
368
369 static const char builtin_types[][10] = {
370 "", /* 0x00, */
371 "Object",
372 "Class",
373 "Module",
374 "Float",
375 "String",
376 "Regexp",
377 "Array",
378 "Hash",
379 "Struct",
380 "Bignum",
381 "File",
382 "Data", /* internal use: wrapped C pointers */
383 "MatchData", /* data of $~ */
384 "Complex",
385 "Rational",
386 "", /* 0x10 */
387 "nil",
388 "true",
389 "false",
390 "Symbol", /* :symbol */
391 "Fixnum",
392 "", /* 0x16 */
393 "", /* 0x17 */
394 "", /* 0x18 */
395 "", /* 0x19 */
396 "", /* 0x1a */
397 "undef", /* internal use: #undef; should not happen */
398 "Node", /* internal use: syntax tree node */
399 "iClass", /* internal use: mixed-in module holder */
400 };
401
402 const char *
403 rb_builtin_type_name(int t)
404 {
405 const char *name;
406 if ((unsigned int)t >= numberof(builtin_types)) return 0;
407 name = builtin_types[t];
408 if (*name) return name;
409 return 0;
410 }
411
412 #define builtin_class_name rb_builtin_class_name
413 const char *
414 rb_builtin_class_name(VALUE x)
415 {
416 const char *etype;
417
418 if (NIL_P(x)) {
419 etype = "nil";
420 }
421 else if (FIXNUM_P(x)) {
422 etype = "Fixnum";
423 }
424 else if (SYMBOL_P(x)) {
425 etype = "Symbol";
426 }
427 else if (RB_TYPE_P(x, T_TRUE)) {
428 etype = "true";
429 }
430 else if (RB_TYPE_P(x, T_FALSE)) {
431 etype = "false";
432 }
433 else {
434 etype = rb_obj_classname(x);
435 }
436 return etype;
437 }
438
439 void
440 rb_check_type(VALUE x, int t)
441 {
442 int xt;
443
444 if (x == Qundef) {
445 rb_bug("undef leaked to the Ruby space");
446 }
447
448 xt = TYPE(x);
449 if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
450 const char *tname = rb_builtin_type_name(t);
451 if (tname) {
452 rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
453 builtin_class_name(x), tname);
454 }
455 if (xt > T_MASK && xt <= 0x3f) {
456 rb_fatal("unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt);
457 }
458 rb_bug("unknown type 0x%x (0x%x given)", t, xt);
459 }
460 }
461
462 int
463 rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
464 {
465 while (child) {
466 if (child == parent) return 1;
467 child = child->parent;
468 }
469 return 0;
470 }
471
472 int
473 rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
474 {
475 if (!RB_TYPE_P(obj, T_DATA) ||
476 !RTYPEDDATA_P(obj) || !rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
477 return 0;
478 }
479 return 1;
480 }
481
482 void *
483 rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
484 {
485 const char *etype;
486 static const char mesg[] = "wrong argument type %s (expected %s)";
487
488 if (!RB_TYPE_P(obj, T_DATA)) {
489 etype = builtin_class_name(obj);
490 rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
491 }
492 if (!RTYPEDDATA_P(obj)) {
493 etype = rb_obj_classname(obj);
494 rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
495 }
496 else if (!rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
497 etype = RTYPEDDATA_TYPE(obj)->wrap_struct_name;
498 rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
499 }
500 return DATA_PTR(obj);
501 }
502
503 /* exception classes */
504 VALUE rb_eException;
505 VALUE rb_eSystemExit;
506 VALUE rb_eInterrupt;
507 VALUE rb_eSignal;
508 VALUE rb_eFatal;
509 VALUE rb_eStandardError;
510 VALUE rb_eRuntimeError;
511 VALUE rb_eTypeError;
512 VALUE rb_eArgError;
513 VALUE rb_eIndexError;
514 VALUE rb_eKeyError;
515 VALUE rb_eRangeError;
516 VALUE rb_eNameError;
517 VALUE rb_eEncodingError;
518 VALUE rb_eEncCompatError;
519 VALUE rb_eNoMethodError;
520 VALUE rb_eSecurityError;
521 VALUE rb_eNotImpError;
522 VALUE rb_eNoMemError;
523 VALUE rb_cNameErrorMesg;
524
525 VALUE rb_eScriptError;
526 VALUE rb_eSyntaxError;
527 VALUE rb_eLoadError;
528
529 VALUE rb_eSystemCallError;
530 VALUE rb_mErrno;
531 static VALUE rb_eNOERROR;
532
533 #undef rb_exc_new2
534
535 VALUE
536 rb_exc_new(VALUE etype, const char *ptr, long len)
537 {
538 return rb_funcall(etype, rb_intern("new"), 1, rb_str_new(ptr, len));
539 }
540
541 VALUE
542 rb_exc_new2(VALUE etype, const char *s)
543 {
544 return rb_exc_new(etype, s, strlen(s));
545 }
546
547 VALUE
548 rb_exc_new3(VALUE etype, VALUE str)
549 {
550 StringValue(str);
551 return rb_funcall(etype, rb_intern("new"), 1, str);
552 }
553
554 /*
555 * call-seq:
556 * Exception.new(msg = nil) -> exception
557 *
558 * Construct a new Exception object, optionally passing in
559 * a message.
560 */
561
562 static VALUE
563 exc_initialize(int argc, VALUE *argv, VALUE exc)
564 {
565 VALUE arg;
566
567 rb_scan_args(argc, argv, "01", &arg);
568 rb_iv_set(exc, "mesg", arg);
569 rb_iv_set(exc, "bt", Qnil);
570
571 return exc;
572 }
573
574 /*
575 * Document-method: exception
576 *
577 * call-seq:
578 * exc.exception(string) -> an_exception or exc
579 *
580 * With no argument, or if the argument is the same as the receiver,
581 * return the receiver. Otherwise, create a new
582 * exception object of the same class as the receiver, but with a
583 * message equal to <code>string.to_str</code>.
584 *
585 */
586
587 static VALUE
588 exc_exception(int argc, VALUE *argv, VALUE self)
589 {
590 VALUE exc;
591
592 if (argc == 0) return self;
593 if (argc == 1 && self == argv[0]) return self;
594 exc = rb_obj_clone(self);
595 exc_initialize(argc, argv, exc);
596
597 return exc;
598 }
599
600 /*
601 * call-seq:
602 * exception.to_s -> string
603 *
604 * Returns exception's message (or the name of the exception if
605 * no message is set).
606 */
607
608 static VALUE
609 exc_to_s(VALUE exc)
610 {
611 VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
612 VALUE r = Qnil;
613
614 if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
615 r = rb_String(mesg);
616 return r;
617 }
618
619 /*
620 * call-seq:
621 * exception.message -> string
622 *
623 * Returns the result of invoking <code>exception.to_s</code>.
624 * Normally this returns the exception's message or name. By
625 * supplying a to_str method, exceptions are agreeing to
626 * be used where Strings are expected.
627 */
628
629 static VALUE
630 exc_message(VALUE exc)
631 {
632 return rb_funcall(exc, rb_intern("to_s"), 0, 0);
633 }
634
635 /*
636 * call-seq:
637 * exception.inspect -> string
638 *
639 * Return this exception's class name and message
640 */
641
642 static VALUE
643 exc_inspect(VALUE exc)
644 {
645 VALUE str, klass;
646
647 klass = CLASS_OF(exc);
648 exc = rb_obj_as_string(exc);
649 if (RSTRING_LEN(exc) == 0) {
650 return rb_str_dup(rb_class_name(klass));
651 }
652
653 str = rb_str_buf_new2("#<");
654 klass = rb_class_name(klass);
655 rb_str_buf_append(str, klass);
656 rb_str_buf_cat(str, ": ", 2);
657 rb_str_buf_append(str, exc);
658 rb_str_buf_cat(str, ">", 1);
659
660 return str;
661 }
662
663 /*
664 * call-seq:
665 * exception.backtrace -> array
666 *
667 * Returns any backtrace associated with the exception. The backtrace
668 * is an array of strings, each containing either ``filename:lineNo: in
669 * `method''' or ``filename:lineNo.''
670 *
671 * def a
672 * raise "boom"
673 * end
674 *
675 * def b
676 * a()
677 * end
678 *
679 * begin
680 * b()
681 * rescue => detail
682 * print detail.backtrace.join("\n")
683 * end
684 *
685 * <em>produces:</em>
686 *
687 * prog.rb:2:in `a'
688 * prog.rb:6:in `b'
689 * prog.rb:10
690 */
691
692 static VALUE
693 exc_backtrace(VALUE exc)
694 {
695 ID bt;
696 VALUE obj;
697
698 CONST_ID(bt, "bt");
699 obj = rb_attr_get(exc, bt);
700
701 if (rb_backtrace_p(obj)) {
702 obj = rb_backtrace_to_str_ary(obj);
703 /* rb_iv_set(exc, "bt", obj); */
704 }
705
706 return obj;
707 }
708
709 VALUE
710 rb_check_backtrace(VALUE bt)
711 {
712 long i;
713 static const char err[] = "backtrace must be Array of String";
714
715 if (!NIL_P(bt)) {
716 if (RB_TYPE_P(bt, T_STRING)) return rb_ary_new3(1, bt);
717 if (rb_backtrace_p(bt)) return bt;
718 if (!RB_TYPE_P(bt, T_ARRAY)) {
719 rb_raise(rb_eTypeError, err);
720 }
721 for (i=0;i<RARRAY_LEN(bt);i++) {
722 if (!RB_TYPE_P(RARRAY_PTR(bt)[i], T_STRING)) {
723 rb_raise(rb_eTypeError, err);
724 }
725 }
726 }
727 return bt;
728 }
729
730 /*
731 * call-seq:
732 * exc.set_backtrace(backtrace) -> array
733 *
734 * Sets the backtrace information associated with +exc+. The +backtrace+ must
735 * be an array of String objects or a single String in the format described
736 * in Exception#backtrace.
737 *
738 */
739
740 static VALUE
741 exc_set_backtrace(VALUE exc, VALUE bt)
742 {
743 return rb_iv_set(exc, "bt", rb_check_backtrace(bt));
744 }
745
746 VALUE
747 rb_exc_set_backtrace(VALUE exc, VALUE bt)
748 {
749 return exc_set_backtrace(exc, bt);
750 }
751
752 static VALUE
753 try_convert_to_exception(VALUE obj)
754 {
755 ID id_exception;
756 CONST_ID(id_exception, "exception");
757 return rb_check_funcall(obj, id_exception, 0, 0);
758 }
759
760 /*
761 * call-seq:
762 * exc == obj -> true or false
763 *
764 * Equality---If <i>obj</i> is not an <code>Exception</code>, returns
765 * <code>false</code>. Otherwise, returns <code>true</code> if <i>exc</i> and
766 * <i>obj</i> share same class, messages, and backtrace.
767 */
768
769 static VALUE
770 exc_equal(VALUE exc, VALUE obj)
771 {
772 VALUE mesg, backtrace;
773 ID id_mesg;
774
775 if (exc == obj) return Qtrue;
776 CONST_ID(id_mesg, "mesg");
777
778 if (rb_obj_class(exc) != rb_obj_class(obj)) {
779 int status = 0;
780 ID id_message, id_backtrace;
781 CONST_ID(id_message, "message");
782 CONST_ID(id_backtrace, "backtrace");
783
784 obj = rb_protect(try_convert_to_exception, obj, &status);
785 if (status || obj == Qundef) {
786 rb_set_errinfo(Qnil);
787 return Qfalse;
788 }
789 if (rb_obj_class(exc) != rb_obj_class(obj)) return Qfalse;
790 mesg = rb_check_funcall(obj, id_message, 0, 0);
791 if (mesg == Qundef) return Qfalse;
792 backtrace = rb_check_funcall(obj, id_backtrace, 0, 0);
793 if (backtrace == Qundef) return Qfalse;
794 }
795 else {
796 mesg = rb_attr_get(obj, id_mesg);
797 backtrace = exc_backtrace(obj);
798 }
799
800 if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
801 return Qfalse;
802 if (!rb_equal(exc_backtrace(exc), backtrace))
803 return Qfalse;
804 return Qtrue;
805 }
806
807 /*
808 * call-seq:
809 * SystemExit.new -> system_exit
810 * SystemExit.new(status) -> system_exit
811 * SystemExit.new(status, msg) -> system_exit
812 * SystemExit.new(msg) -> system_exit
813 *
814 * Create a new +SystemExit+ exception with the given status and message.
815 * Status is true, false, or an integer.
816 * If status is not given, true is used.
817 */
818
819 static VALUE
820 exit_initialize(int argc, VALUE *argv, VALUE exc)
821 {
822 VALUE status;
823 if (argc > 0) {
824 status = *argv;
825
826 switch (status) {
827 case Qtrue:
828 status = INT2FIX(EXIT_SUCCESS);
829 ++argv;
830 --argc;
831 break;
832 case Qfalse:
833 status = INT2FIX(EXIT_FAILURE);
834 ++argv;
835 --argc;
836 break;
837 default:
838 status = rb_check_to_int(status);
839 if (NIL_P(status)) {
840 status = INT2FIX(EXIT_SUCCESS);
841 }
842 else {
843 #if EXIT_SUCCESS != 0
844 if (status == INT2FIX(0))
845 status = INT2FIX(EXIT_SUCCESS);
846 #endif
847 ++argv;
848 --argc;
849 }
850 break;
851 }
852 }
853 else {
854 status = INT2FIX(EXIT_SUCCESS);
855 }
856 rb_call_super(argc, argv);
857 rb_iv_set(exc, "status", status);
858 return exc;
859 }
860
861
862 /*
863 * call-seq:
864 * system_exit.status -> fixnum
865 *
866 * Return the status value associated with this system exit.
867 */
868
869 static VALUE
870 exit_status(VALUE exc)
871 {
872 return rb_attr_get(exc, rb_intern("status"));
873 }
874
875
876 /*
877 * call-seq:
878 * system_exit.success? -> true or false
879 *
880 * Returns +true+ if exiting successful, +false+ if not.
881 */
882
883 static VALUE
884 exit_success_p(VALUE exc)
885 {
886 VALUE status_val = rb_attr_get(exc, rb_intern("status"));
887 int status;
888
889 if (NIL_P(status_val))
890 return Qtrue;
891 status = NUM2INT(status_val);
892 if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)
893 return Qtrue;
894
895 return Qfalse;
896 }
897
898 void
899 rb_name_error(ID id, const char *fmt, ...)
900 {
901 VALUE exc, argv[2];
902 va_list args;
903
904 va_start(args, fmt);
905 argv[0] = rb_vsprintf(fmt, args);
906 va_end(args);
907
908 argv[1] = ID2SYM(id);
909 exc = rb_class_new_instance(2, argv, rb_eNameError);
910 rb_exc_raise(exc);
911 }
912
913 void
914 rb_name_error_str(VALUE str, const char *fmt, ...)
915 {
916 VALUE exc, argv[2];
917 va_list args;
918
919 va_start(args, fmt);
920 argv[0] = rb_vsprintf(fmt, args);
921 va_end(args);
922
923 argv[1] = str;
924 exc = rb_class_new_instance(2, argv, rb_eNameError);
925 rb_exc_raise(exc);
926 }
927
928 /*
929 * call-seq:
930 * NameError.new(msg [, name]) -> name_error
931 *
932 * Construct a new NameError exception. If given the <i>name</i>
933 * parameter may subsequently be examined using the <code>NameError.name</code>
934 * method.
935 */
936
937 static VALUE
938 name_err_initialize(int argc, VALUE *argv, VALUE self)
939 {
940 VALUE name;
941
942 name = (argc > 1) ? argv[--argc] : Qnil;
943 rb_call_super(argc, argv);
944 rb_iv_set(self, "name", name);
945 return self;
946 }
947
948 /*
949 * call-seq:
950 * name_error.name -> string or nil
951 *
952 * Return the name associated with this NameError exception.
953 */
954
955 static VALUE
956 name_err_name(VALUE self)
957 {
958 return rb_attr_get(self, rb_intern("name"));
959 }
960
961 /*
962 * call-seq:
963 * name_error.to_s -> string
964 *
965 * Produce a nicely-formatted string representing the +NameError+.
966 */
967
968 static VALUE
969 name_err_to_s(VALUE exc)
970 {
971 VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
972 VALUE str = mesg;
973
974 if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
975 StringValue(str);
976 return str;
977 }
978
979 /*
980 * call-seq:
981 * NoMethodError.new(msg, name [, args]) -> no_method_error
982 *
983 * Construct a NoMethodError exception for a method of the given name
984 * called with the given arguments. The name may be accessed using
985 * the <code>#name</code> method on the resulting object, and the
986 * arguments using the <code>#args</code> method.
987 */
988
989 static VALUE
990 nometh_err_initialize(int argc, VALUE *argv, VALUE self)
991 {
992 VALUE args = (argc > 2) ? argv[--argc] : Qnil;
993 name_err_initialize(argc, argv, self);
994 rb_iv_set(self, "args", args);
995 return self;
996 }
997
998 /* :nodoc: */
999 #define NAME_ERR_MESG_COUNT 3
1000
1001 static void
1002 name_err_mesg_mark(void *p)
1003 {
1004 VALUE *ptr = p;
1005 rb_gc_mark_locations(ptr, ptr+NAME_ERR_MESG_COUNT);
1006 }
1007
1008 #define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
1009
1010 static size_t
1011 name_err_mesg_memsize(const void *p)
1012 {
1013 return p ? (NAME_ERR_MESG_COUNT * sizeof(VALUE)) : 0;
1014 }
1015
1016 static const rb_data_type_t name_err_mesg_data_type = {
1017 "name_err_mesg",
1018 {
1019 name_err_mesg_mark,
1020 name_err_mesg_free,
1021 name_err_mesg_memsize,
1022 },
1023 };
1024
1025 /* :nodoc: */
1026 VALUE
1027 rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
1028 {
1029 VALUE *ptr = ALLOC_N(VALUE, NAME_ERR_MESG_COUNT);
1030 VALUE result;
1031
1032 ptr[0] = mesg;
1033 ptr[1] = recv;
1034 ptr[2] = method;
1035 result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, ptr);
1036 RB_GC_GUARD(mesg);
1037 RB_GC_GUARD(recv);
1038 RB_GC_GUARD(method);
1039 return result;
1040 }
1041
1042 /* :nodoc: */
1043 static VALUE
1044 name_err_mesg_equal(VALUE obj1, VALUE obj2)
1045 {
1046 VALUE *ptr1, *ptr2;
1047 int i;
1048
1049 if (obj1 == obj2) return Qtrue;
1050 if (rb_obj_class(obj2) != rb_cNameErrorMesg)
1051 return Qfalse;
1052
1053 TypedData_Get_Struct(obj1, VALUE, &name_err_mesg_data_type, ptr1);
1054 TypedData_Get_Struct(obj2, VALUE, &name_err_mesg_data_type, ptr2);
1055 for (i=0; i<NAME_ERR_MESG_COUNT; i++) {
1056 if (!rb_equal(ptr1[i], ptr2[i]))
1057 return Qfalse;
1058 }
1059 return Qtrue;
1060 }
1061
1062 /* :nodoc: */
1063 static VALUE
1064 name_err_mesg_to_str(VALUE obj)
1065 {
1066 VALUE *ptr, mesg;
1067 TypedData_Get_Struct(obj, VALUE, &name_err_mesg_data_type, ptr);
1068
1069 mesg = ptr[0];
1070 if (NIL_P(mesg)) return Qnil;
1071 else {
1072 const char *desc = 0;
1073 VALUE d = 0, args[NAME_ERR_MESG_COUNT];
1074 int state = 0;
1075
1076 obj = ptr[1];
1077 switch (obj) {
1078 case Qnil:
1079 desc = "nil";
1080 break;
1081 case Qtrue:
1082 desc = "true";
1083 break;
1084 case Qfalse:
1085 desc = "false";
1086 break;
1087 default:
1088 d = rb_protect(rb_inspect, obj, &state);
1089 if (state)
1090 rb_set_errinfo(Qnil);
1091 if (NIL_P(d) || RSTRING_LEN(d) > 65) {
1092 d = rb_any_to_s(obj);
1093 }
1094 desc = RSTRING_PTR(d);
1095 break;
1096 }
1097 if (desc && desc[0] != '#') {
1098 d = d ? rb_str_dup(d) : rb_str_new2(desc);
1099 rb_str_cat2(d, ":");
1100 rb_str_append(d, rb_class_name(CLASS_OF(obj)));
1101 }
1102 args[0] = mesg;
1103 args[1] = ptr[2];
1104 args[2] = d;
1105 mesg = rb_f_sprintf(NAME_ERR_MESG_COUNT, args);
1106 }
1107 return mesg;
1108 }
1109
1110 /* :nodoc: */
1111 static VALUE
1112 name_err_mesg_dump(VALUE obj, VALUE limit)
1113 {
1114 return name_err_mesg_to_str(obj);
1115 }
1116
1117 /* :nodoc: */
1118 static VALUE
1119 name_err_mesg_load(VALUE klass, VALUE str)
1120 {
1121 return str;
1122 }
1123
1124 /*
1125 * call-seq:
1126 * no_method_error.args -> obj
1127 *
1128 * Return the arguments passed in as the third parameter to
1129 * the constructor.
1130 */
1131
1132 static VALUE
1133 nometh_err_args(VALUE self)
1134 {
1135 return rb_attr_get(self, rb_intern("args"));
1136 }
1137
1138 void
1139 rb_invalid_str(const char *str, const char *type)
1140 {
1141 VALUE s = rb_str_new2(str);
1142
1143 rb_raise(rb_eArgError, "invalid value for %s: %+"PRIsVALUE, type, s);
1144 }
1145
1146 /*
1147 * Document-module: Errno
1148 *
1149 * Ruby exception objects are subclasses of <code>Exception</code>.
1150 * However, operating systems typically report errors using plain
1151 * integers. Module <code>Errno</code> is created dynamically to map
1152 * these operating system errors to Ruby classes, with each error
1153 * number generating its own subclass of <code>SystemCallError</code>.
1154 * As the subclass is created in module <code>Errno</code>, its name
1155 * will start <code>Errno::</code>.
1156 *
1157 * The names of the <code>Errno::</code> classes depend on
1158 * the environment in which Ruby runs. On a typical Unix or Windows
1159 * platform, there are <code>Errno</code> classes such as
1160 * <code>Errno::EACCES</code>, <code>Errno::EAGAIN</code>,
1161 * <code>Errno::EINTR</code>, and so on.
1162 *
1163 * The integer operating system error number corresponding to a
1164 * particular error is available as the class constant
1165 * <code>Errno::</code><em>error</em><code>::Errno</code>.
1166 *
1167 * Errno::EACCES::Errno #=> 13
1168 * Errno::EAGAIN::Errno #=> 11
1169 * Errno::EINTR::Errno #=> 4
1170 *
1171 * The full list of operating system errors on your particular platform
1172 * are available as the constants of <code>Errno</code>.
1173 *
1174 * Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
1175 */
1176
1177 static st_table *syserr_tbl;
1178
1179 static VALUE
1180 set_syserr(int n, const char *name)
1181 {
1182 st_data_t error;
1183
1184 if (!st_lookup(syserr_tbl, n, &error)) {
1185 error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);
1186 rb_define_const(error, "Errno", INT2NUM(n));
1187 st_add_direct(syserr_tbl, n, error);
1188 }
1189 else {
1190 rb_define_const(rb_mErrno, name, error);
1191 }
1192 return error;
1193 }
1194
1195 static VALUE
1196 get_syserr(int n)
1197 {
1198 st_data_t error;
1199
1200 if (!st_lookup(syserr_tbl, n, &error)) {
1201 char name[8]; /* some Windows' errno have 5 digits. */
1202
1203 snprintf(name, sizeof(name), "E%03d", n);
1204 error = set_syserr(n, name);
1205 }
1206 return error;
1207 }
1208
1209 /*
1210 * call-seq:
1211 * SystemCallError.new(msg, errno) -> system_call_error_subclass
1212 *
1213 * If _errno_ corresponds to a known system error code, constructs
1214 * the appropriate <code>Errno</code> class for that error, otherwise
1215 * constructs a generic <code>SystemCallError</code> object. The
1216 * error number is subsequently available via the <code>errno</code>
1217 * method.
1218 */
1219
1220 static VALUE
1221 syserr_initialize(int argc, VALUE *argv, VALUE self)
1222 {
1223 #if !defined(_WIN32)
1224 char *strerror();
1225 #endif
1226 const char *err;
1227 VALUE mesg, error;
1228 VALUE klass = rb_obj_class(self);
1229
1230 if (klass == rb_eSystemCallError) {
1231 st_data_t data = (st_data_t)klass;
1232 rb_scan_args(argc, argv, "11", &mesg, &error);
1233 if (argc == 1 && FIXNUM_P(mesg)) {
1234 error = mesg; mesg = Qnil;
1235 }
1236 if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
1237 klass = (VALUE)data;
1238 /* change class */
1239 if (!RB_TYPE_P(self, T_OBJECT)) { /* insurance to avoid type crash */
1240 rb_raise(rb_eTypeError, "invalid instance type");
1241 }
1242 RBASIC(self)->klass = klass;
1243 }
1244 }
1245 else {
1246 rb_scan_args(argc, argv, "01", &mesg);
1247 error = rb_const_get(klass, rb_intern("Errno"));
1248 }
1249 if (!NIL_P(error)) err = strerror(NUM2INT(error));
1250 else err = "unknown error";
1251 if (!NIL_P(mesg)) {
1252 rb_encoding *le = rb_locale_encoding();
1253 VALUE str = StringValue(mesg);
1254 rb_encoding *me = rb_enc_get(mesg);
1255
1256 mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
1257 if (le != me && rb_enc_asciicompat(me)) {
1258 le = me;
1259 }/* else assume err is non ASCII string. */
1260 OBJ_INFECT(mesg, str);
1261 rb_enc_associate(mesg, le);
1262 }
1263 else {
1264 mesg = rb_str_new2(err);
1265 rb_enc_associate(mesg, rb_locale_encoding());
1266 }
1267 rb_call_super(1, &mesg);
1268 rb_iv_set(self, "errno", error);
1269 return self;
1270 }
1271
1272 /*
1273 * call-seq:
1274 * system_call_error.errno -> fixnum
1275 *
1276 * Return this SystemCallError's error number.
1277 */
1278
1279 static VALUE
1280 syserr_errno(VALUE self)
1281 {
1282 return rb_attr_get(self, rb_intern("errno"));
1283 }
1284
1285 /*
1286 * call-seq:
1287 * system_call_error === other -> true or false
1288 *
1289 * Return +true+ if the receiver is a generic +SystemCallError+, or
1290 * if the error numbers +self+ and _other_ are the same.
1291 */
1292
1293 static VALUE
1294 syserr_eqq(VALUE self, VALUE exc)
1295 {
1296 VALUE num, e;
1297 ID en;
1298
1299 CONST_ID(en, "errno");
1300
1301 if (!rb_obj_is_kind_of(exc, rb_eSystemCallError)) {
1302 if (!rb_respond_to(exc, en)) return Qfalse;
1303 }
1304 else if (self == rb_eSystemCallError) return Qtrue;
1305
1306 num = rb_attr_get(exc, rb_intern("errno"));
1307 if (NIL_P(num)) {
1308 num = rb_funcall(exc, en, 0, 0);
1309 }
1310 e = rb_const_get(self, rb_intern("Errno"));
1311 if (FIXNUM_P(num) ? num == e : rb_equal(num, e))
1312 return Qtrue;
1313 return Qfalse;
1314 }
1315
1316
1317 /*
1318 * Document-class: StandardError
1319 *
1320 * The most standard error types are subclasses of StandardError. A
1321 * rescue clause without an explicit Exception class will rescue all
1322 * StandardErrors (and only those).
1323 *
1324 * def foo
1325 * raise "Oups"
1326 * end
1327 * foo rescue "Hello" #=> "Hello"
1328 *
1329 * On the other hand:
1330 *
1331 * require 'does/not/exist' rescue "Hi"
1332 *
1333 * <em>raises the exception:</em>
1334 *
1335 * LoadError: no such file to load -- does/not/exist
1336 *
1337 */
1338
1339 /*
1340 * Document-class: SystemExit
1341 *
1342 * Raised by +exit+ to initiate the termination of the script.
1343 */
1344
1345 /*
1346 * Document-class: SignalException
1347 *
1348 * Raised when a signal is received.
1349 *
1350 * begin
1351 * Process.kill('HUP',Process.pid)
1352 * sleep # wait for receiver to handle signal sent by Process.kill
1353 * rescue SignalException => e
1354 * puts "received Exception #{e}"
1355 * end
1356 *
1357 * <em>produces:</em>
1358 *
1359 * received Exception SIGHUP
1360 */
1361
1362 /*
1363 * Document-class: Interrupt
1364 *
1365 * Raised with the interrupt signal is received, typically because the
1366 * user pressed on Control-C (on most posix platforms). As such, it is a
1367 * subclass of +SignalException+.
1368 *
1369 * begin
1370 * puts "Press ctrl-C when you get bored"
1371 * loop {}
1372 * rescue Interrupt => e
1373 * puts "Note: You will typically use Signal.trap instead."
1374 * end
1375 *
1376 * <em>produces:</em>
1377 *
1378 * Press ctrl-C when you get bored
1379 *
1380 * <em>then waits until it is interrupted with Control-C and then prints:</em>
1381 *
1382 * Note: You will typically use Signal.trap instead.
1383 */
1384
1385 /*
1386 * Document-class: TypeError
1387 *
1388 * Raised when encountering an object that is not of the expected type.
1389 *
1390 * [1, 2, 3].first("two")
1391 *
1392 * <em>raises the exception:</em>
1393 *
1394 * TypeError: no implicit conversion of String into Integer
1395 *
1396 */
1397
1398 /*
1399 * Document-class: ArgumentError
1400 *
1401 * Raised when the arguments are wrong and there isn't a more specific
1402 * Exception class.
1403 *
1404 * Ex: passing the wrong number of arguments
1405 *
1406 * [1, 2, 3].first(4, 5)
1407 *
1408 * <em>raises the exception:</em>
1409 *
1410 * ArgumentError: wrong number of arguments (2 for 1)
1411 *
1412 * Ex: passing an argument that is not acceptable:
1413 *
1414 * [1, 2, 3].first(-4)
1415 *
1416 * <em>raises the exception:</em>
1417 *
1418 * ArgumentError: negative array size
1419 */
1420
1421 /*
1422 * Document-class: IndexError
1423 *
1424 * Raised when the given index is invalid.
1425 *
1426 * a = [:foo, :bar]
1427 * a.fetch(0) #=> :foo
1428 * a[4] #=> nil
1429 * a.fetch(4) #=> IndexError: index 4 outside of array bounds: -2...2
1430 *
1431 */
1432
1433 /*
1434 * Document-class: KeyError
1435 *
1436 * Raised when the specified key is not found. It is a subclass of
1437 * IndexError.
1438 *
1439 * h = {"foo" => :bar}
1440 * h.fetch("foo") #=> :bar
1441 * h.fetch("baz") #=> KeyError: key not found: "baz"
1442 *
1443 */
1444
1445 /*
1446 * Document-class: RangeError
1447 *
1448 * Raised when a given numerical value is out of range.
1449 *
1450 * [1, 2, 3].drop(1 << 100)
1451 *
1452 * <em>raises the exception:</em>
1453 *
1454 * RangeError: bignum too big to convert into `long'
1455 */
1456
1457 /*
1458 * Document-class: ScriptError
1459 *
1460 * ScriptError is the superclass for errors raised when a script
1461 * can not be executed because of a +LoadError+,
1462 * +NotImplementedError+ or a +SyntaxError+. Note these type of
1463 * +ScriptErrors+ are not +StandardError+ and will not be
1464 * rescued unless it is specified explicitly (or its ancestor
1465 * +Exception+).
1466 */
1467
1468 /*
1469 * Document-class: SyntaxError
1470 *
1471 * Raised when encountering Ruby code with an invalid syntax.
1472 *
1473 * eval("1+1=2")
1474 *
1475 * <em>raises the exception:</em>
1476 *
1477 * SyntaxError: (eval):1: syntax error, unexpected '=', expecting $end
1478 */
1479
1480 /*
1481 * Document-class: LoadError
1482 *
1483 * Raised when a file required (a Ruby script, extension library, ...)
1484 * fails to load.
1485 *
1486 * require 'this/file/does/not/exist'
1487 *
1488 * <em>raises the exception:</em>
1489 *
1490 * LoadError: no such file to load -- this/file/does/not/exist
1491 */
1492
1493 /*
1494 * Document-class: NotImplementedError
1495 *
1496 * Raised when a feature is not implemented on the current platform. For
1497 * example, methods depending on the +fsync+ or +fork+ system calls may
1498 * raise this exception if the underlying operating system or Ruby
1499 * runtime does not support them.
1500 *
1501 * Note that if +fork+ raises a +NotImplementedError+, then
1502 * <code>respond_to?(:fork)</code> returns +false+.
1503 */
1504
1505 /*
1506 * Document-class: NameError
1507 *
1508 * Raised when a given name is invalid or undefined.
1509 *
1510 * puts foo
1511 *
1512 * <em>raises the exception:</em>
1513 *
1514 * NameError: undefined local variable or method `foo' for main:Object
1515 *
1516 * Since constant names must start with a capital:
1517 *
1518 * Fixnum.const_set :answer, 42
1519 *
1520 * <em>raises the exception:</em>
1521 *
1522 * NameError: wrong constant name answer
1523 */
1524
1525 /*
1526 * Document-class: NoMethodError
1527 *
1528 * Raised when a method is called on a receiver which doesn't have it
1529 * defined and also fails to respond with +method_missing+.
1530 *
1531 * "hello".to_ary
1532 *
1533 * <em>raises the exception:</em>
1534 *
1535 * NoMethodError: undefined method `to_ary' for "hello":String
1536 */
1537
1538 /*
1539 * Document-class: RuntimeError
1540 *
1541 * A generic error class raised when an invalid operation is attempted.
1542 *
1543 * [1, 2, 3].freeze << 4
1544 *
1545 * <em>raises the exception:</em>
1546 *
1547 * RuntimeError: can't modify frozen array
1548 *
1549 * Kernel.raise will raise a RuntimeError if no Exception class is
1550 * specified.
1551 *
1552 * raise "ouch"
1553 *
1554 * <em>raises the exception:</em>
1555 *
1556 * RuntimeError: ouch
1557 */
1558
1559 /*
1560 * Document-class: SecurityError
1561 *
1562 * Raised when attempting a potential unsafe operation, typically when
1563 * the $SAFE level is raised above 0.
1564 *
1565 * foo = "bar"
1566 * proc = Proc.new do
1567 * $SAFE = 4
1568 * foo.gsub! "a", "*"
1569 * end
1570 * proc.call
1571 *
1572 * <em>raises the exception:</em>
1573 *
1574 * SecurityError: Insecure: can't modify string
1575 */
1576
1577 /*
1578 * Document-class: NoMemoryError
1579 *
1580 * Raised when memory allocation fails.
1581 */
1582
1583 /*
1584 * Document-class: SystemCallError
1585 *
1586 * SystemCallError is the base class for all low-level
1587 * platform-dependent errors.
1588 *
1589 * The errors available on the current platform are subclasses of
1590 * SystemCallError and are defined in the Errno module.
1591 *
1592 * File.open("does/not/exist")
1593 *
1594 * <em>raises the exception:</em>
1595 *
1596 * Errno::ENOENT: No such file or directory - does/not/exist
1597 */
1598
1599 /*
1600 * Document-class: EncodingError
1601 *
1602 * EncodingError is the base class for encoding errors.
1603 */
1604
1605 /*
1606 * Document-class: Encoding::CompatibilityError
1607 *
1608 * Raised by Encoding and String methods when the source encoding is
1609 * incompatible with the target encoding.
1610 */
1611
1612 /*
1613 * Document-class: fatal
1614 *
1615 * fatal is an Exception that is raised when ruby has encountered a fatal
1616 * error and must exit. You are not able to rescue fatal.
1617 */
1618
1619 /*
1620 * Document-class: NameError::message
1621 * :nodoc:
1622 */
1623
1624 /*
1625 * Descendants of class Exception are used to communicate between
1626 * Kernel#raise and +rescue+ statements in <code>begin ... end</code> blocks.
1627 * Exception objects carry information about the exception -- its type (the
1628 * exception's class name), an optional descriptive string, and optional
1629 * traceback information. Exception subclasses may add additional
1630 * information like NameError#name.
1631 *
1632 * Programs may make subclasses of Exception, typically of StandardError or
1633 * RuntimeError, to provide custom classes and add additional information.
1634 * See the subclass list below for defaults for +raise+ and +rescue+.
1635 *
1636 * When an exception has been raised but not yet handled (in +rescue+,
1637 * +ensure+, +at_exit+ and +END+ blocks) the global variable <code>$!</code>
1638 * will contain the current exception and <code>$@</code> contains the
1639 * current exception's backtrace.
1640 *
1641 * It is recommended that a library should have one subclass of StandardError
1642 * or RuntimeError and have specific exception types inherit from it. This
1643 * allows the user to rescue a generic exception type to catch all exceptions
1644 * the library may raise even if future versions of the library add new
1645 * exception subclasses.
1646 *
1647 * For example:
1648 *
1649 * class MyLibrary
1650 * class Error < RuntimeError
1651 * end
1652 *
1653 * class WidgetError < Error
1654 * end
1655 *
1656 * class FrobError < Error
1657 * end
1658 *
1659 * end
1660 *
1661 * To handle both WidgetError and FrobError the library user can rescue
1662 * MyLibrary::Error.
1663 *
1664 * The built-in subclasses of Exception are:
1665 *
1666 * * NoMemoryError
1667 * * ScriptError
1668 * * LoadError
1669 * * NotImplementedError
1670 * * SyntaxError
1671 * * SignalException
1672 * * Interrupt
1673 * * StandardError -- default for +rescue+
1674 * * ArgumentError
1675 * * IndexError
1676 * * StopIteration
1677 * * IOError
1678 * * EOFError
1679 * * LocalJumpError
1680 * * NameError
1681 * * NoMethodError
1682 * * RangeError
1683 * * FloatDomainError
1684 * * RegexpError
1685 * * RuntimeError -- default for +raise+
1686 * * SecurityError
1687 * * SystemCallError
1688 * * Errno::*
1689 * * SystemStackError
1690 * * ThreadError
1691 * * TypeError
1692 * * ZeroDivisionError
1693 * * SystemExit
1694 * * fatal -- impossible to rescue
1695 */
1696
1697 void
1698 Init_Exception(void)
1699 {
1700 rb_eException = rb_define_class("Exception", rb_cObject);
1701 rb_define_singleton_method(rb_eException, "exception", rb_class_new_instance, -1);
1702 rb_define_method(rb_eException, "exception", exc_exception, -1);
1703 rb_define_method(rb_eException, "initialize", exc_initialize, -1);
1704 rb_define_method(rb_eException, "==", exc_equal, 1);
1705 rb_define_method(rb_eException, "to_s", exc_to_s, 0);
1706 rb_define_method(rb_eException, "message", exc_message, 0);
1707 rb_define_method(rb_eException, "inspect", exc_inspect, 0);
1708 rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
1709 rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
1710
1711 rb_eSystemExit = rb_define_class("SystemExit", rb_eException);
1712 rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1);
1713 rb_define_method(rb_eSystemExit, "status", exit_status, 0);
1714 rb_define_method(rb_eSystemExit, "success?", exit_success_p, 0);
1715
1716 rb_eFatal = rb_define_class("fatal", rb_eException);
1717 rb_eSignal = rb_define_class("SignalException", rb_eException);
1718 rb_eInterrupt = rb_define_class("Interrupt", rb_eSignal);
1719
1720 rb_eStandardError = rb_define_class("StandardError", rb_eException);
1721 rb_eTypeError = rb_define_class("TypeError", rb_eStandardError);
1722 rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError);
1723 rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
1724 rb_eKeyError = rb_define_class("KeyError", rb_eIndexError);
1725 rb_eRangeError = rb_define_class("RangeError", rb_eStandardError);
1726
1727 rb_eScriptError = rb_define_class("ScriptError", rb_eException);
1728 rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);
1729
1730 rb_eLoadError = rb_define_class("LoadError", rb_eScriptError);
1731 rb_attr(rb_eLoadError, rb_intern("path"), 1, 0, Qfalse);
1732
1733 rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError);
1734
1735 rb_eNameError = rb_define_class("NameError", rb_eStandardError);
1736 rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1);
1737 rb_define_method(rb_eNameError, "name", name_err_name, 0);
1738 rb_define_method(rb_eNameError, "to_s", name_err_to_s, 0);
1739 rb_cNameErrorMesg = rb_define_class_under(rb_eNameError, "message", rb_cData);
1740 rb_define_singleton_method(rb_cNameErrorMesg, "!", rb_name_err_mesg_new, NAME_ERR_MESG_COUNT);
1741 rb_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1);
1742 rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0);
1743 rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_dump, 1);
1744 rb_define_singleton_method(rb_cNameErrorMesg, "_load", name_err_mesg_load, 1);
1745 rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError);
1746 rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1);
1747 rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0);
1748
1749 rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError);
1750 rb_eSecurityError = rb_define_class("SecurityError", rb_eException);
1751 rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
1752 rb_eEncodingError = rb_define_class("EncodingError", rb_eStandardError);
1753 rb_eEncCompatError = rb_define_class_under(rb_cEncoding, "CompatibilityError", rb_eEncodingError);
1754
1755 syserr_tbl = st_init_numtable();
1756 rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError);
1757 rb_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1);
1758 rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0);
1759 rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
1760
1761 rb_mErrno = rb_define_module("Errno");
1762
1763 rb_define_global_function("warn", rb_warn_m, -1);
1764 }
1765
1766 void
1767 rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
1768 {
1769 va_list args;
1770 VALUE mesg;
1771
1772 va_start(args, fmt);
1773 mesg = rb_enc_vsprintf(enc, fmt, args);
1774 va_end(args);
1775
1776 rb_exc_raise(rb_exc_new3(exc, mesg));
1777 }
1778
1779 void
1780 rb_raise(VALUE exc, const char *fmt, ...)
1781 {
1782 va_list args;
1783 VALUE mesg;
1784
1785 va_start(args, fmt);
1786 mesg = rb_vsprintf(fmt, args);
1787 va_end(args);
1788 rb_exc_raise(rb_exc_new3(exc, mesg));
1789 }
1790
1791 NORETURN(static void raise_loaderror(VALUE path, VALUE mesg));
1792
1793 static void
1794 raise_loaderror(VALUE path, VALUE mesg)
1795 {
1796 VALUE err = rb_exc_new3(rb_eLoadError, mesg);
1797 rb_ivar_set(err, rb_intern("@path"), path);
1798 rb_exc_raise(err);
1799 }
1800
1801 void
1802 rb_loaderror(const char *fmt, ...)
1803 {
1804 va_list args;
1805 VALUE mesg;
1806
1807 va_start(args, fmt);
1808 mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
1809 va_end(args);
1810 raise_loaderror(Qnil, mesg);
1811 }
1812
1813 void
1814 rb_loaderror_with_path(VALUE path, const char *fmt, ...)
1815 {
1816 va_list args;
1817 VALUE mesg;
1818
1819 va_start(args, fmt);
1820 mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
1821 va_end(args);
1822 raise_loaderror(path, mesg);
1823 }
1824
1825 void
1826 rb_notimplement(void)
1827 {
1828 rb_raise(rb_eNotImpError,
1829 "%s() function is unimplemented on this machine",
1830 rb_id2name(rb_frame_this_func()));
1831 }
1832
1833 void
1834 rb_fatal(const char *fmt, ...)
1835 {
1836 va_list args;
1837 VALUE mesg;
1838
1839 va_start(args, fmt);
1840 mesg = rb_vsprintf(fmt, args);
1841 va_end(args);
1842
1843 rb_exc_fatal(rb_exc_new3(rb_eFatal, mesg));
1844 }
1845
1846 static VALUE
1847 make_errno_exc(const char *mesg)
1848 {
1849 int n = errno;
1850
1851 errno = 0;
1852 if (n == 0) {
1853 rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : "");
1854 }
1855 return rb_syserr_new(n, mesg);
1856 }
1857
1858 static VALUE
1859 make_errno_exc_str(VALUE mesg)
1860 {
1861 int n = errno;
1862
1863 errno = 0;
1864 if (!mesg) mesg = Qnil;
1865 if (n == 0) {
1866 const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : "";
1867 rb_bug("rb_sys_fail_str(%s) - errno == 0", s);
1868 }
1869 return rb_syserr_new_str(n, mesg);
1870 }
1871
1872 VALUE
1873 rb_syserr_new(int n, const char *mesg)
1874 {
1875 VALUE arg;
1876 arg = mesg ? rb_str_new2(mesg) : Qnil;
1877 return rb_syserr_new_str(n, arg);
1878 }
1879
1880 VALUE
1881 rb_syserr_new_str(int n, VALUE arg)
1882 {
1883 return rb_class_new_instance(1, &arg, get_syserr(n));
1884 }
1885
1886 void
1887 rb_syserr_fail(int e, const char *mesg)
1888 {
1889 rb_exc_raise(rb_syserr_new(e, mesg));
1890 }
1891
1892 void
1893 rb_syserr_fail_str(int e, VALUE mesg)
1894 {
1895 rb_exc_raise(rb_syserr_new_str(e, mesg));
1896 }
1897
1898 void
1899 rb_sys_fail(const char *mesg)
1900 {
1901 rb_exc_raise(make_errno_exc(mesg));
1902 }
1903
1904 void
1905 rb_sys_fail_str(VALUE mesg)
1906 {
1907 rb_exc_raise(make_errno_exc_str(mesg));
1908 }
1909
1910 void
1911 rb_mod_sys_fail(VALUE mod, const char *mesg)
1912 {
1913 VALUE exc = make_errno_exc(mesg);
1914 rb_extend_object(exc, mod);
1915 rb_exc_raise(exc);
1916 }
1917
1918 void
1919 rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
1920 {
1921 VALUE exc = make_errno_exc_str(mesg);
1922 rb_extend_object(exc, mod);
1923 rb_exc_raise(exc);
1924 }
1925
1926 void
1927 rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
1928 {
1929 VALUE exc = rb_syserr_new(e, mesg);
1930 rb_extend_object(exc, mod);
1931 rb_exc_raise(exc);
1932 }
1933
1934 void
1935 rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
1936 {
1937 VALUE exc = rb_syserr_new_str(e, mesg);
1938 rb_extend_object(exc, mod);
1939 rb_exc_raise(exc);
1940 }
1941
1942 void
1943 rb_sys_warning(const char *fmt, ...)
1944 {
1945 char buf[BUFSIZ];
1946 va_list args;
1947 int errno_save;
1948
1949 errno_save = errno;
1950
1951 if (!RTEST(ruby_verbose)) return;
1952
1953 snprintf(buf, BUFSIZ, "warning: %s", fmt);
1954 snprintf(buf+strlen(buf), BUFSIZ-strlen(buf), ": %s", strerror(errno_save));
1955
1956 va_start(args, fmt);
1957 warn_print(buf, args);
1958 va_end(args);
1959 errno = errno_save;
1960 }
1961
1962 void
1963 rb_load_fail(VALUE path, const char *err)
1964 {
1965 VALUE mesg = rb_str_buf_new_cstr(err);
1966 rb_str_cat2(mesg, " -- ");
1967 rb_str_append(mesg, path); /* should be ASCII compatible */
1968 raise_loaderror(path, mesg);
1969 }
1970
1971 void
1972 rb_error_frozen(const char *what)
1973 {
1974 rb_raise(rb_eRuntimeError, "can't modify frozen %s", what);
1975 }
1976
1977 #undef rb_check_frozen
1978 void
1979 rb_check_frozen(VALUE obj)
1980 {
1981 rb_check_frozen_internal(obj);
1982 }
1983
1984 void
1985 rb_error_untrusted(VALUE obj)
1986 {
1987 if (rb_safe_level() >= 4) {
1988 rb_raise(rb_eSecurityError, "Insecure: can't modify %s",
1989 rb_obj_classname(obj));
1990 }
1991 }
1992
1993 #undef rb_check_trusted
1994 void
1995 rb_check_trusted(VALUE obj)
1996 {
1997 rb_check_trusted_internal(obj);
1998 }
1999
2000 void
2001 rb_check_copyable(VALUE obj, VALUE orig)
2002 {
2003 if (!FL_ABLE(obj)) return;
2004 rb_check_frozen_internal(obj);
2005 rb_check_trusted_internal(obj);
2006 if (!FL_ABLE(orig)) return;
2007 if ((~RBASIC(obj)->flags & RBASIC(orig)->flags) & (FL_UNTRUSTED|FL_TAINT)) {
2008 if (rb_safe_level() > 0) {
2009 rb_raise(rb_eSecurityError, "Insecure: can't modify %"PRIsVALUE,
2010 RBASIC(obj)->klass);
2011 }
2012 }
2013 }
2014
2015 void
2016 Init_syserr(void)
2017 {
2018 rb_eNOERROR = set_syserr(0, "NOERROR");
2019 #define defined_error(name, num) set_syserr((num), (name));
2020 #define undefined_error(name) set_syserr(0, (name));
2021 #include "known_errors.inc"
2022 #undef defined_error
2023 #undef undefined_error
2024 }
data
VALUE data
Definition: tcltklib.c:3368
rb_eScriptError
VALUE rb_eScriptError
Definition: error.c:525
RB_TYPE_P
#define RB_TYPE_P(obj, type)
rb_check_frozen_internal
#define rb_check_frozen_internal(obj)
RARRAY_PTR
RARRAY_PTR(q->result)[0]
rb_builtin_class_name
const char * rb_builtin_class_name(VALUE x)
Definition: error.c:414
syserr_errno
static VALUE syserr_errno(VALUE self)
Definition: error.c:1280
rb_eStandardError
VALUE rb_eStandardError
Definition: error.c:509
compile_err_append
static void compile_err_append(VALUE mesg)
Definition: error.c:92
make_errno_exc_str
static VALUE make_errno_exc_str(VALUE mesg)
Definition: error.c:1859
rb_exc_new
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Definition: error.c:536
exc_backtrace
static VALUE exc_backtrace(VALUE exc)
Definition: error.c:693
n
ssize_t n
Definition: bigdecimal.c:5655
rb_any_to_s
VALUE rb_any_to_s(VALUE)
Definition: object.c:384
rb_bug
void rb_bug(const char *fmt,...)
Definition: error.c:290
name_err_mesg_data_type
static const rb_data_type_t name_err_mesg_data_type
Definition: error.c:1016
get_syserr
static VALUE get_syserr(int n)
Definition: error.c:1196
rb_compile_error
void rb_compile_error(const char *file, int line, const char *fmt,...)
Definition: error.c:138
th
static VALUE VALUE th
Definition: tcltklib.c:2948
rb_gc_mark_locations
#define rb_gc_mark_locations(start, end)
Definition: gc.c:2346
strlen
size_t strlen(const char *)
OBJ_INFECT
#define OBJ_INFECT(x, s)
rb_class_new_instance
VALUE rb_class_new_instance(int, VALUE *, VALUE)
Definition: object.c:1775
st_table
Definition: ripper.y:77
rb_obj_classname
const char * rb_obj_classname(VALUE)
Definition: variable.c:396
p
Win32OLEIDispatch * p
Definition: win32ole.c:786
rb_iv_set
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:2591
rb_syserr_fail
void rb_syserr_fail(int e, const char *mesg)
Definition: error.c:1887
rb_cEncoding
VALUE rb_cEncoding
Definition: encoding.c:40
rb_eSignal
VALUE rb_eSignal
Definition: error.c:507
exc_message
static VALUE exc_message(VALUE exc)
Definition: error.c:630
st_lookup
int st_lookup(st_table *, st_data_t, st_data_t *)
st_add_direct
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:624
rb_check_trusted
#define rb_check_trusted(obj)
rb_define_singleton_method
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1497
rb_str_buf_append
VALUE rb_str_buf_append(VALUE, VALUE)
Definition: string.c:2105
rb_eKeyError
VALUE rb_eKeyError
Definition: error.c:514
ruby.h
out
C_block * out
Definition: crypt.c:308
rb_io_puts
VALUE rb_io_puts(int, VALUE *, VALUE)
Definition: io.c:6890
st_init_numtable
st_table * st_init_numtable(void)
Definition: st.c:272
rb_const_get
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1876
i
ssize_t i
Definition: bigdecimal.c:5655
rb_error_frozen
void rb_error_frozen(const char *what)
Definition: error.c:1972
name_err_mesg_memsize
static size_t name_err_mesg_memsize(const void *p)
Definition: error.c:1011
rb_syserr_new_str
VALUE rb_syserr_new_str(int n, VALUE arg)
Definition: error.c:1881
rb_check_frozen
#define rb_check_frozen(obj)
rb_builtin_type_name
const char * rb_builtin_type_name(int t)
Definition: error.c:403
rb_frame_this_func
ID rb_frame_this_func(void)
Definition: eval.c:902
status
int status
Definition: tcltklib.c:2197
rb_block_struct
Definition: vm_core.h:442
exc_to_s
static VALUE exc_to_s(VALUE exc)
Definition: error.c:609
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:511
rb_name_err_mesg_new
VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1027
rb_cNameErrorMesg
VALUE rb_cNameErrorMesg
Definition: error.c:523
name_err_name
static VALUE name_err_name(VALUE self)
Definition: error.c:956
exc
VALUE exc
Definition: tcltklib.c:3096
enc
VALUE enc
Definition: tcltklib.c:10311
rb_eEncodingError
VALUE rb_eEncodingError
Definition: error.c:517
path
gz path
Definition: zlib.c:2279
TYPE
#define TYPE(x)
RSTRING_PTR
#define RSTRING_PTR(str)
CLASS_OF
#define CLASS_OF(v)
NIL_P
NIL_P(eventloop_thread)
Definition: tcltklib.c:4068
T_ARRAY
#define T_ARRAY
rb_enc_str_new
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
Definition: string.c:439
WIFEXITED
#define WIFEXITED(status)
Definition: error.c:35
rb_async_bug_errno
void rb_async_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:334
rb_protect
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:771
rb_funcall
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:774
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:545
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1780
Qtrue
return Qtrue
Definition: tcltklib.c:9610
rb_enc_associate
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
Definition: encoding.c:766
rb_obj_class
VALUE rb_obj_class(VALUE)
Definition: object.c:194
rb_check_trusted_internal
#define rb_check_trusted_internal(obj)
rb_compile_warn
void rb_compile_warn(const char *file, int line, const char *fmt,...)
Definition: error.c:172
rb_class_name
VALUE rb_class_name(VALUE)
Definition: variable.c:383
rb_backtrace_to_str_ary
VALUE rb_backtrace_to_str_ary(VALUE obj)
Definition: vm_backtrace.c:586
rb_ary_new3
VALUE rb_ary_new3(long n,...)
Definition: array.c:432
rb_eSecurityError
VALUE rb_eSecurityError
Definition: error.c:520
exc_set_backtrace
static VALUE exc_set_backtrace(VALUE exc, VALUE bt)
Definition: error.c:741
r
r
Definition: bigdecimal.c:1196
FL_UNTRUSTED
#define FL_UNTRUSTED
name_err_initialize
static VALUE name_err_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:938
rb_str_new2
#define rb_str_new2
rb_define_global_function
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1526
state
int state
Definition: tcltklib.c:1462
syserr_eqq
static VALUE syserr_eqq(VALUE self, VALUE exc)
Definition: error.c:1294
WEXITSTATUS
#define WEXITSTATUS(status)
Definition: error.c:39
rb_eSyntaxError
VALUE rb_eSyntaxError
Definition: error.c:526
rb_thread_struct
Definition: vm_core.h:493
ID2SYM
#define ID2SYM(x)
rb_load_fail
void rb_load_fail(VALUE path, const char *err)
Definition: error.c:1963
args
VALUE VALUE args
Definition: tcltklib.c:2561
rb_loaderror
void rb_loaderror(const char *fmt,...)
Definition: error.c:1802
T_OBJECT
#define T_OBJECT
syserr_tbl
static st_table * syserr_tbl
Definition: error.c:1177
rb_str_append
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2121
rb_f_sprintf
VALUE rb_f_sprintf(int, const VALUE *)
Definition: sprintf.c:433
rb_equal
VALUE rb_equal(VALUE, VALUE)
Definition: object.c:56
rb_eRangeError
VALUE rb_eRangeError
Definition: error.c:515
d
d
Definition: strlcat.c:58
rb_name_error_str
void rb_name_error_str(VALUE str, const char *fmt,...)
Definition: error.c:914
fmt
const char * fmt
Definition: tcltklib.c:841
exc_exception
static VALUE exc_exception(int argc, VALUE *argv, VALUE self)
Definition: error.c:588
rb_name_error
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:899
__sFILE
Definition: vsnprintf.c:175
rb_loaderror_with_path
void rb_loaderror_with_path(VALUE path, const char *fmt,...)
Definition: error.c:1814
NORETURN
#define NORETURN(x)
Definition: ruby.h:31
rb_exc_raise
void rb_exc_raise(VALUE mesg)
Definition: eval.c:527
st_data_t
unsigned long st_data_t
Definition: ripper.y:35
rb_eNameError
VALUE rb_eNameError
Definition: error.c:516
le
#define le(x, y)
Definition: time.c:69
Qfalse
return Qfalse
Definition: tcltklib.c:6779
FIXNUM_P
#define FIXNUM_P(f)
rb_compile_bug
void rb_compile_bug(const char *file, int line, const char *fmt,...)
Definition: error.c:358
TypedData_Get_Struct
#define TypedData_Get_Struct(obj, type, data_type, sval)
rb_compile_error_append
void rb_compile_error_append(const char *fmt,...)
Definition: error.c:150
rb_compile_error_with_enc
void rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt,...)
Definition: error.c:126
RARRAY_LEN
#define RARRAY_LEN(a)
Qnil
#define Qnil
Definition: tcltklib.c:1896
rb_eRuntimeError
VALUE rb_eRuntimeError
Definition: error.c:510
rb_data_type_struct::parent
const rb_data_type_t * parent
Definition: ripper.y:969
vsnprintf
vsnprintf(buf, BUFSIZ, fmt, args)
name_err_mesg_dump
static VALUE name_err_mesg_dump(VALUE obj, VALUE limit)
Definition: error.c:1112
rb_syserr_new
VALUE rb_syserr_new(int n, const char *mesg)
Definition: error.c:1873
str
static VALUE char * str
Definition: tcltklib.c:3547
exc_equal
static VALUE exc_equal(VALUE exc, VALUE obj)
Definition: error.c:770
rb_typeddata_is_kind_of
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:473
flags
int flags
Definition: tcltklib.c:3023
ID
unsigned long ID
Definition: ripper.y:105
va_end
va_end(args)
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2202
rb_str_cat2
VALUE rb_str_cat2(VALUE, const char *)
Definition: string.c:1982
rb_define_class
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:499
try_convert_to_exception
static VALUE try_convert_to_exception(VALUE obj)
Definition: error.c:753
rb_eNoMethodError
VALUE rb_eNoMethodError
Definition: error.c:519
obj
static VALUE VALUE obj
Definition: tcltklib.c:3158
RSTRING_LEN
#define RSTRING_LEN(str)
exit_success_p
static VALUE exit_success_p(VALUE exc)
Definition: error.c:884
INT2FIX
#define INT2FIX(i)
name_err_mesg_free
#define name_err_mesg_free
Definition: error.c:1008
unistd.h
rb_sys_fail_str
void rb_sys_fail_str(VALUE mesg)
Definition: error.c:1905
nometh_err_args
static VALUE nometh_err_args(VALUE self)
Definition: error.c:1133
rb_eNoMemError
VALUE rb_eNoMemError
Definition: error.c:522
T_STRING
#define T_STRING
name_err_mesg_to_str
static VALUE name_err_mesg_to_str(VALUE obj)
Definition: error.c:1064
rb_check_type
void rb_check_type(VALUE x, int t)
Definition: error.c:440
method
volatile ID method
Definition: tcltklib.c:3599
rb_vm_bugreport
void rb_vm_bugreport(void)
Definition: vm_dump.c:609
rb_call_super
VALUE rb_call_super(int, const VALUE *)
Definition: vm_eval.c:273
write_or_abort
#define write_or_abort(fd, str, len)
Definition: error.c:330
rb_sourcefile
#define rb_sourcefile()
Definition: tcltklib.c:97
set_syserr
static VALUE set_syserr(int n, const char *name)
Definition: error.c:1180
TypedData_Wrap_Struct
#define TypedData_Wrap_Struct(klass, data_type, sval)
exit_status
static VALUE exit_status(VALUE exc)
Definition: error.c:870
rb_mod_syserr_fail_str
void rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
Definition: error.c:1935
rb_thread_struct::base_block
rb_block_t * base_block
Definition: vm_core.h:524
buf
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4308
rb_enc_raise
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
Definition: error.c:1767
rb_eEncCompatError
VALUE rb_eEncCompatError
Definition: error.c:518
err
int err
Definition: win32.c:87
rb_exc_set_backtrace
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
Definition: error.c:747
EXIT_FAILURE
#define EXIT_FAILURE
Definition: eval_intern.h:24
rb_mErrno
VALUE rb_mErrno
Definition: error.c:530
rb_str_buf_new_cstr
VALUE rb_str_buf_new_cstr(const char *)
Definition: string.c:793
Init_Exception
void Init_Exception(void)
Definition: error.c:1698
rb_eLoadError
VALUE rb_eLoadError
Definition: error.c:527
rb_check_funcall
VALUE rb_check_funcall(VALUE, ID, int, VALUE *)
Definition: vm_eval.c:408
rb_eIndexError
VALUE rb_eIndexError
Definition: error.c:513
encoding.h
rb_str_buf_cat
VALUE rb_str_buf_cat(VALUE, const char *, long)
Definition: string.c:1947
rb_str_dup
VALUE rb_str_dup(VALUE)
Definition: string.c:946
name_err_mesg_equal
static VALUE name_err_mesg_equal(VALUE obj1, VALUE obj2)
Definition: error.c:1044
compile_snprintf
static VALUE compile_snprintf(rb_encoding *enc, const char *pre, const char *file, int line, const char *fmt, va_list args)
Definition: error.c:77
rb_obj_as_string
VALUE rb_obj_as_string(VALUE)
Definition: string.c:895
argv
VALUE * argv
Definition: tcltklib.c:1971
RTEST
#define RTEST(v)
Init_syserr
void Init_syserr(void)
Definition: error.c:2016
rb_obj_clone
VALUE rb_obj_clone(VALUE)
Definition: object.c:296
errno
int errno
result
q result
Definition: tcltklib.c:7070
EXIT_SUCCESS
#define EXIT_SUCCESS
Definition: error.c:31
rb_sprintf
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1270
builtin_types
static const char builtin_types[][10]
Definition: error.c:369
StringValue
#define StringValue(v)
rb_fatal
void rb_fatal(const char *fmt,...)
Definition: error.c:1834
RTYPEDDATA_P
#define RTYPEDDATA_P(v)
rb_eSystemCallError
VALUE rb_eSystemCallError
Definition: error.c:529
s
register char * s
Definition: os2.c:56
CONST_ID
#define CONST_ID(var, str)
rb_String
VALUE rb_String(VALUE)
Definition: object.c:2738
rb_scan_args
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1570
numberof
#define numberof(array)
Definition: error.c:28
internal.h
rb_eInterrupt
VALUE rb_eInterrupt
Definition: error.c:506
rb_attr
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:796
exc_initialize
static VALUE exc_initialize(int argc, VALUE *argv, VALUE exc)
Definition: error.c:563
rb_exc_new2
VALUE rb_exc_new2(VALUE etype, const char *s)
Definition: error.c:542
RB_GC_GUARD
#define RB_GC_GUARD(v)
type
int type
Definition: tcltklib.c:111
FL_TAINT
#define FL_TAINT
REPORTBUG_MSG
#define REPORTBUG_MSG
Definition: error.c:44
vm_core.h
argc
int argc
Definition: tcltklib.c:1970
rb_locale_encoding
rb_encoding * rb_locale_encoding(void)
Definition: encoding.c:1214
err_position_0
static int err_position_0(char *buf, long len, const char *file, int line)
Definition: error.c:63
rb_extend_object
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:1234
rb_mod_syserr_fail
void rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
Definition: error.c:1927
rb_warn_m
static VALUE rb_warn_m(int argc, VALUE *argv, VALUE exc)
Definition: error.c:257
rb_bug_errno
void rb_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:313
exit_initialize
static VALUE exit_initialize(int argc, VALUE *argv, VALUE exc)
Definition: error.c:820
rb_enc_vsprintf
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
Definition: sprintf.c:1218
rb_attr_get
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1122
rb_check_copyable
void rb_check_copyable(VALUE obj, VALUE orig)
Definition: error.c:2001
rb_sourceline
int rb_sourceline(void)
Definition: vm.c:816
rb_sys_fail
void rb_sys_fail(const char *mesg)
Definition: error.c:1899
syserr_initialize
static VALUE syserr_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:1221
ruby_verbose
ruby_verbose
Definition: tcltklib.c:5818
ptr
return ptr
Definition: tcltklib.c:784
FL_ABLE
#define FL_ABLE(x)
rb_strerrno
static const char * rb_strerrno(int err)
Definition: error.c:52
rb_vsprintf
VALUE rb_vsprintf(const char *, va_list)
Definition: sprintf.c:1264
WRITE_CONST
#define WRITE_CONST(fd, str)
Definition: error.c:331
strerror
RUBY_EXTERN char * strerror(int)
Definition: strerror.c:11
T_TRUE
#define T_TRUE
NAME_ERR_MESG_COUNT
#define NAME_ERR_MESG_COUNT
Definition: error.c:999
name_err_to_s
static VALUE name_err_to_s(VALUE exc)
Definition: error.c:969
rb_ivar_set
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1128
arg
arg
Definition: ripper.y:1315
rb_stderr
RUBY_EXTERN VALUE rb_stderr
Definition: ripper.y:1500
rb_str_buf_new2
#define rb_str_buf_new2
rb_enc_get
rb_encoding * rb_enc_get(VALUE obj)
Definition: encoding.c:772
rb_mod_sys_fail_str
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
Definition: error.c:1919
NUM2LONG
#define NUM2LONG(x)
SYMBOL_P
#define SYMBOL_P(x)
rb_check_to_int
VALUE rb_check_to_int(VALUE)
Definition: object.c:2437
rb_check_typeddata
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:483
Qundef
#define Qundef
rb_obj_is_kind_of
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:582
rb_exc_new3
VALUE rb_exc_new3(VALUE etype, VALUE str)
Definition: error.c:548
rb_thread_struct::mild_compile_error
int mild_compile_error
Thread-local state of compiling context.
Definition: vm_core.h:576
nometh_err_initialize
static VALUE nometh_err_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:990
t
int t
Definition: ripper.c:14699
rb_set_errinfo
void rb_set_errinfo(VALUE err)
Definition: eval.c:1436
rb_mod_sys_fail
void rb_mod_sys_fail(VALUE mod, const char *mesg)
Definition: error.c:1911
rb_data_type_struct
Definition: ripper.y:960
DATA_PTR
DATA_PTR(self)
exc_inspect
static VALUE exc_inspect(VALUE exc)
Definition: error.c:643
rb_str_catf
VALUE rb_str_catf(VALUE str, const char *format,...)
Definition: sprintf.c:1310
rb_syserr_fail_str
void rb_syserr_fail_str(int e, VALUE mesg)
Definition: error.c:1893
rb_compile_warning
void rb_compile_warning(const char *file, int line, const char *fmt,...)
Definition: error.c:185
make_errno_exc
static VALUE make_errno_exc(const char *mesg)
Definition: error.c:1847
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1426
ALLOC_N
#define ALLOC_N(type, n)
RBASIC
#define RBASIC(obj)
rb_data_type_struct::wrap_struct_name
const char * wrap_struct_name
Definition: ripper.y:961
klass
klass
Definition: tcltklib.c:3504
INT2NUM
#define INT2NUM(x)
rb_str_vcatf
VALUE rb_str_vcatf(VALUE, const char *, va_list)
Definition: sprintf.c:1283
rb_respond_to
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:1564
rb_check_backtrace
VALUE rb_check_backtrace(VALUE bt)
Definition: error.c:710
rb_notimplement
void rb_notimplement(void)
Definition: error.c:1826
st.h
rb_eNotImpError
VALUE rb_eNotImpError
Definition: error.c:521
raise_loaderror
static void raise_loaderror(VALUE path, VALUE mesg)
Definition: error.c:1794
rb_str_new
VALUE rb_str_new(const char *, long)
Definition: string.c:425
rb_safe_level
#define rb_safe_level()
Definition: tcltklib.c:94
builtin_class_name
#define builtin_class_name
Definition: error.c:412
rb_typeddata_inherited_p
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
Definition: error.c:463
compile_warn_print
static void compile_warn_print(const char *file, int line, const char *fmt, va_list args)
Definition: error.c:162
rb_backtrace_p
int rb_backtrace_p(VALUE obj)
Definition: vm_backtrace.c:413
ruby_description
const char ruby_description[]
Definition: version.c:64
report_bug
static void report_bug(const char *file, int line, const char *fmt, va_list args)
Definition: error.c:266
rb_enc_asciicompat
#define rb_enc_asciicompat(enc)
NUM2INT
#define NUM2INT(x)
rb_id2name
const char * rb_id2name(ID id)
Definition: ripper.c:17005
rb_eFatal
VALUE rb_eFatal
Definition: error.c:508
rb_error_untrusted
void rb_error_untrusted(VALUE obj)
Definition: error.c:1985
PRIsVALUE
#define PRIsVALUE
e
BDIGIT e
Definition: bigdecimal.c:5085
warn_print
static void warn_print(const char *fmt, va_list args)
Definition: error.c:197
VALUE
unsigned long VALUE
Definition: ripper.y:104
rb_warning
void rb_warning(const char *fmt,...)
Definition: error.c:229
snprintf
#define snprintf
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:617
rb_intern
#define rb_intern(str)
mod
#define mod(x, y)
Definition: date_strftime.c:28
rb_cData
RUBY_EXTERN VALUE rb_cData
Definition: ripper.y:1433
rb_exc_fatal
void rb_exc_fatal(VALUE mesg)
Definition: eval.c:536
rb_eSystemExit
VALUE rb_eSystemExit
Definition: error.c:505
NULL
#define NULL
Definition: _sdbm.c:103
T_DATA
#define T_DATA
name
const char * name
Definition: nkf.c:208
rb_thread_struct::errinfo
VALUE errinfo
Definition: vm_core.h:542
rb_write_error_str
void rb_write_error_str(VALUE mesg)
Definition: io.c:7070
GET_THREAD
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:883
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1344
rb_warn
void rb_warn(const char *fmt,...)
Definition: error.c:216
rb_invalid_str
void rb_invalid_str(const char *str, const char *type)
Definition: error.c:1139
rb_eArgError
VALUE rb_eArgError
Definition: error.c:512
T_MASK
#define T_MASK
Definition: md5.c:131
RTYPEDDATA_TYPE
#define RTYPEDDATA_TYPE(v)
T_FALSE
#define T_FALSE
name_err_mesg_load
static VALUE name_err_mesg_load(VALUE klass, VALUE str)
Definition: error.c:1119
rb_sys_warning
void rb_sys_warning(const char *fmt,...)
Definition: error.c:1943
name_err_mesg_mark
static void name_err_mesg_mark(void *p)
Definition: error.c:1002
rb_eException
VALUE rb_eException
Definition: error.c:504
rb_inspect
VALUE rb_inspect(VALUE)
Definition: object.c:402
OnigEncodingTypeST
Definition: ripper.y:161
rb_eNOERROR
static VALUE rb_eNOERROR
Definition: error.c:531
rb_sourcefilename
VALUE rb_sourcefilename(void)
Definition: vm.c:788
len
size_t len
Definition: tcltklib.c:3568