magnus/exception.rs
1//! Types and functions for working with Ruby exceptions.
2//!
3//! See also [`Ruby`](Ruby#core-exceptions) for more exception related methods.
4
5use std::fmt;
6
7#[cfg(ruby_gte_3_1)]
8use rb_sys::rb_eNoMatchingPatternKeyError;
9use rb_sys::{
10 rb_eArgError, rb_eEOFError, rb_eEncCompatError, rb_eEncodingError, rb_eException, rb_eFatal,
11 rb_eFloatDomainError, rb_eFrozenError, rb_eIOError, rb_eIndexError, rb_eInterrupt,
12 rb_eKeyError, rb_eLoadError, rb_eLocalJumpError, rb_eMathDomainError, rb_eNameError,
13 rb_eNoMatchingPatternError, rb_eNoMemError, rb_eNoMethodError, rb_eNotImpError, rb_eRangeError,
14 rb_eRegexpError, rb_eRuntimeError, rb_eScriptError, rb_eSecurityError, rb_eSignal,
15 rb_eStandardError, rb_eStopIteration, rb_eSyntaxError, rb_eSysStackError, rb_eSystemCallError,
16 rb_eSystemExit, rb_eThreadError, rb_eTypeError, rb_eZeroDivError, VALUE,
17};
18
19use crate::{
20 class::{Class, RClass},
21 error::Error,
22 into_value::{ArgList, IntoValue},
23 module::Module,
24 object::Object,
25 r_array::RArray,
26 try_convert::TryConvert,
27 value::{
28 private::{self, ReprValue as _},
29 NonZeroValue, ReprValue, Value,
30 },
31 Ruby,
32};
33
34/// Wrapper type for a Value known to be an instance of Ruby's Exception class.
35///
36/// See the [`ReprValue`] and [`Object`] traits for additional methods
37/// available on this type.
38#[derive(Clone, Copy)]
39#[repr(transparent)]
40pub struct Exception(NonZeroValue);
41
42impl Exception {
43 /// Return `Some(Exception)` if `val` is an `Exception`, `None` otherwise.
44 ///
45 /// # Examples
46 ///
47 /// ```
48 /// use magnus::{eval, Exception};
49 /// # let _cleanup = unsafe { magnus::embed::init() };
50 ///
51 /// assert!(Exception::from_value(eval(r#"StandardError.new("example")"#).unwrap()).is_some());
52 /// assert!(Exception::from_value(eval("Object.new").unwrap()).is_none());
53 /// ```
54 #[inline]
55 pub fn from_value(val: Value) -> Option<Self> {
56 debug_assert_value!(val);
57 unsafe {
58 val.class()
59 .is_inherited(RClass::from_rb_value_unchecked(rb_eException))
60 .then(|| Self(NonZeroValue::new_unchecked(val)))
61 }
62 }
63
64 #[inline]
65 pub(crate) unsafe fn from_rb_value_unchecked(val: VALUE) -> Self {
66 Self(NonZeroValue::new_unchecked(Value::new(val)))
67 }
68
69 /// Returns the class that `self` is an instance of, as an
70 /// [`ExceptionClass`].
71 ///
72 /// See also [`ReprValue::class`].
73 ///
74 /// # Examples
75 ///
76 /// ```
77 /// use magnus::{eval, prelude::*, Exception};
78 /// # let _cleanup = unsafe { magnus::embed::init() };
79 ///
80 /// let e: Exception = eval(r#"StandardError.new("example")"#).unwrap();
81 /// let ec = e.exception_class();
82 /// // safe as we immediately create an owned String and drop the reference
83 /// assert_eq!(unsafe { ec.name().to_owned() }, "StandardError");
84 /// ```
85 pub fn exception_class(self) -> ExceptionClass {
86 unsafe { ExceptionClass::from_rb_value_unchecked(self.class().as_rb_value()) }
87 }
88}
89
90impl fmt::Display for Exception {
91 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92 write!(f, "{}", unsafe { self.to_s_infallible() })
93 }
94}
95
96impl fmt::Debug for Exception {
97 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98 if f.alternate() {
99 unsafe {
100 writeln!(f, "{}: {}", self.classname(), self)?;
101 if let Ok(Some(backtrace)) = self.funcall::<_, _, Option<RArray>>("backtrace", ()) {
102 for line in backtrace {
103 writeln!(f, "{}", line)?;
104 }
105 }
106 }
107 Ok(())
108 } else {
109 write!(f, "{}", self.inspect())
110 }
111 }
112}
113
114impl IntoValue for Exception {
115 #[inline]
116 fn into_value_with(self, _: &Ruby) -> Value {
117 self.0.get()
118 }
119}
120
121unsafe impl private::ReprValue for Exception {}
122
123impl ReprValue for Exception {}
124
125impl TryConvert for Exception {
126 fn try_convert(val: Value) -> Result<Self, Error> {
127 if let Some(e) = Self::from_value(val) {
128 return Ok(e);
129 }
130 if let Some(Ok(val)) = val.check_funcall::<_, _, Value>("exception", ()) {
131 if let Some(e) = Self::from_value(val) {
132 return Ok(e);
133 }
134 }
135 Err(Error::new(
136 Ruby::get_with(val).exception_type_error(),
137 format!("no implicit conversion of {} into Exception", unsafe {
138 val.classname()
139 },),
140 ))
141 }
142}
143
144/// A Value known to be an instance of Class and subclass of Exception.
145///
146/// See the [`ReprValue`] and [`Object`] traits for additional methods
147/// available on this type.
148#[derive(Clone, Copy)]
149#[repr(transparent)]
150pub struct ExceptionClass(NonZeroValue);
151
152impl ExceptionClass {
153 /// Return `Some(ExceptionClass)` if `val` is an `ExceptionClass`, `None`
154 /// otherwise.
155 ///
156 /// # Examples
157 ///
158 /// ```
159 /// use magnus::{eval, ExceptionClass};
160 /// # let _cleanup = unsafe { magnus::embed::init() };
161 ///
162 /// assert!(ExceptionClass::from_value(eval("StandardError").unwrap()).is_some());
163 /// assert!(ExceptionClass::from_value(eval(r#"StandardError.new("example")"#).unwrap()).is_none());
164 /// assert!(ExceptionClass::from_value(eval("Object").unwrap()).is_none());
165 /// ```
166 #[inline]
167 pub fn from_value(val: Value) -> Option<Self> {
168 debug_assert_value!(val);
169 unsafe {
170 RClass::from_value(val).and_then(|class| {
171 class
172 .is_inherited(RClass::from_rb_value_unchecked(rb_eException))
173 .then(|| Self(NonZeroValue::new_unchecked(val)))
174 })
175 }
176 }
177
178 #[inline]
179 pub(crate) unsafe fn from_rb_value_unchecked(val: VALUE) -> Self {
180 Self(NonZeroValue::new_unchecked(Value::new(val)))
181 }
182}
183
184impl fmt::Display for ExceptionClass {
185 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
186 write!(f, "{}", unsafe { self.to_s_infallible() })
187 }
188}
189
190impl fmt::Debug for ExceptionClass {
191 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
192 write!(f, "{}", self.inspect())
193 }
194}
195
196impl IntoValue for ExceptionClass {
197 #[inline]
198 fn into_value_with(self, _: &Ruby) -> Value {
199 self.0.get()
200 }
201}
202
203impl Object for ExceptionClass {}
204impl Module for ExceptionClass {}
205
206impl Class for ExceptionClass {
207 type Instance = Exception;
208
209 fn new(superclass: Self) -> Result<Self, Error> {
210 RClass::new(superclass.as_r_class())
211 .map(|class| unsafe { ExceptionClass::from_value_unchecked(class.as_value()) })
212 }
213
214 fn new_instance<T>(self, args: T) -> Result<Self::Instance, Error>
215 where
216 T: ArgList,
217 {
218 self.as_r_class()
219 .new_instance(args)
220 .map(|ins| unsafe { Exception::from_value_unchecked(ins) })
221 }
222
223 fn obj_alloc(self) -> Result<Self::Instance, Error> {
224 self.as_r_class()
225 .obj_alloc()
226 .map(|ins| unsafe { Exception::from_value_unchecked(ins) })
227 }
228
229 fn as_r_class(self) -> RClass {
230 unsafe { RClass::from_value_unchecked(self.as_value()) }
231 }
232}
233
234unsafe impl private::ReprValue for ExceptionClass {}
235
236impl ReprValue for ExceptionClass {}
237
238impl TryConvert for ExceptionClass {
239 fn try_convert(val: Value) -> Result<Self, Error> {
240 Self::from_value(val).ok_or_else(|| {
241 Error::new(
242 Ruby::get_with(val).exception_type_error(),
243 format!(
244 "no implicit conversion of {} into Class inheriting Exception",
245 unsafe { val.classname() },
246 ),
247 )
248 })
249 }
250}
251
252/// # Core Exceptions
253///
254/// Functions to access Ruby's built-in exception classes.
255///
256/// See also the [`exception`](self) module.
257impl Ruby {
258 /// Return Ruby's `ArgumentError` class.
259 ///
260 /// # Examples
261 ///
262 /// ```
263 /// use magnus::{rb_assert, Error, Ruby};
264 ///
265 /// fn example(ruby: &Ruby) -> Result<(), Error> {
266 /// rb_assert!(
267 /// ruby,
268 /// "klass == ArgumentError",
269 /// klass = ruby.exception_arg_error()
270 /// );
271 /// Ok(())
272 /// }
273 /// # Ruby::init(example).unwrap()
274 /// ```
275 #[inline]
276 pub fn exception_arg_error(&self) -> ExceptionClass {
277 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eArgError) }
278 }
279
280 /// Return Ruby's `EOFError` class.
281 ///
282 /// # Examples
283 ///
284 /// ```
285 /// use magnus::{rb_assert, Error, Ruby};
286 ///
287 /// fn example(ruby: &Ruby) -> Result<(), Error> {
288 /// rb_assert!(
289 /// ruby,
290 /// "klass == EOFError",
291 /// klass = ruby.exception_eof_error()
292 /// );
293 /// Ok(())
294 /// }
295 /// # Ruby::init(example).unwrap()
296 /// ```
297 #[inline]
298 pub fn exception_eof_error(&self) -> ExceptionClass {
299 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eEOFError) }
300 }
301
302 /// Return Ruby's `Encoding::CompatibilityError` class.
303 ///
304 /// # Examples
305 ///
306 /// ```
307 /// use magnus::{rb_assert, Error, Ruby};
308 ///
309 /// fn example(ruby: &Ruby) -> Result<(), Error> {
310 /// rb_assert!(
311 /// ruby,
312 /// "klass == Encoding::CompatibilityError",
313 /// klass = ruby.exception_enc_compat_error()
314 /// );
315 /// Ok(())
316 /// }
317 /// # Ruby::init(example).unwrap()
318 /// ```
319 #[inline]
320 pub fn exception_enc_compat_error(&self) -> ExceptionClass {
321 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eEncCompatError) }
322 }
323
324 /// Return Ruby's `EncodingError` class.
325 ///
326 /// # Examples
327 ///
328 /// ```
329 /// use magnus::{rb_assert, Error, Ruby};
330 ///
331 /// fn example(ruby: &Ruby) -> Result<(), Error> {
332 /// rb_assert!(
333 /// ruby,
334 /// "klass == EncodingError",
335 /// klass = ruby.exception_encoding_error()
336 /// );
337 /// Ok(())
338 /// }
339 /// # Ruby::init(example).unwrap()
340 /// ```
341 #[inline]
342 pub fn exception_encoding_error(&self) -> ExceptionClass {
343 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eEncodingError) }
344 }
345
346 /// Return Ruby's `Exception` class.
347 ///
348 /// # Examples
349 ///
350 /// ```
351 /// use magnus::{rb_assert, Error, Ruby};
352 ///
353 /// fn example(ruby: &Ruby) -> Result<(), Error> {
354 /// rb_assert!(
355 /// ruby,
356 /// "klass == Exception",
357 /// klass = ruby.exception_exception()
358 /// );
359 /// Ok(())
360 /// }
361 /// # Ruby::init(example).unwrap()
362 /// ```
363 #[inline]
364 pub fn exception_exception(&self) -> ExceptionClass {
365 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eException) }
366 }
367
368 /// Return Ruby's `fatal` class.
369 ///
370 /// # Examples
371 ///
372 /// ```
373 /// use magnus::{rb_assert, Error, Ruby};
374 ///
375 /// fn example(ruby: &Ruby) -> Result<(), Error> {
376 /// rb_assert!(
377 /// ruby,
378 /// r#"klass.name == "fatal""#,
379 /// klass = ruby.exception_fatal()
380 /// );
381 /// Ok(())
382 /// }
383 /// # Ruby::init(example).unwrap()
384 /// ```
385 #[inline]
386 pub fn exception_fatal(&self) -> ExceptionClass {
387 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eFatal) }
388 }
389
390 /// Return Ruby's `FloatDomainError` class.
391 ///
392 /// # Examples
393 ///
394 /// ```
395 /// use magnus::{rb_assert, Error, Ruby};
396 ///
397 /// fn example(ruby: &Ruby) -> Result<(), Error> {
398 /// rb_assert!(
399 /// ruby,
400 /// "klass == FloatDomainError",
401 /// klass = ruby.exception_float_domain_error()
402 /// );
403 /// Ok(())
404 /// }
405 /// # Ruby::init(example).unwrap()
406 /// ```
407 #[inline]
408 pub fn exception_float_domain_error(&self) -> ExceptionClass {
409 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eFloatDomainError) }
410 }
411
412 /// Return Ruby's `FrozenError` class.
413 ///
414 /// # Examples
415 ///
416 /// ```
417 /// use magnus::{rb_assert, Error, Ruby};
418 ///
419 /// fn example(ruby: &Ruby) -> Result<(), Error> {
420 /// rb_assert!(
421 /// ruby,
422 /// "klass == FrozenError",
423 /// klass = ruby.exception_frozen_error()
424 /// );
425 /// Ok(())
426 /// }
427 /// # Ruby::init(example).unwrap()
428 /// ```
429 #[inline]
430 pub fn exception_frozen_error(&self) -> ExceptionClass {
431 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eFrozenError) }
432 }
433
434 /// Return Ruby's `IOError` class.
435 ///
436 /// # Examples
437 ///
438 /// ```
439 /// use magnus::{rb_assert, Error, Ruby};
440 ///
441 /// fn example(ruby: &Ruby) -> Result<(), Error> {
442 /// rb_assert!(ruby, "klass == IOError", klass = ruby.exception_io_error());
443 /// Ok(())
444 /// }
445 /// # Ruby::init(example).unwrap()
446 /// ```
447 #[inline]
448 pub fn exception_io_error(&self) -> ExceptionClass {
449 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eIOError) }
450 }
451
452 /// Return Ruby's `IndexError` class.
453 ///
454 /// # Examples
455 ///
456 /// ```
457 /// use magnus::{rb_assert, Error, Ruby};
458 ///
459 /// fn example(ruby: &Ruby) -> Result<(), Error> {
460 /// rb_assert!(
461 /// ruby,
462 /// "klass == IndexError",
463 /// klass = ruby.exception_index_error()
464 /// );
465 /// Ok(())
466 /// }
467 /// # Ruby::init(example).unwrap()
468 /// ```
469 #[inline]
470 pub fn exception_index_error(&self) -> ExceptionClass {
471 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eIndexError) }
472 }
473
474 /// Return Ruby's `Interrupt` class.
475 ///
476 /// # Examples
477 ///
478 /// ```
479 /// use magnus::{rb_assert, Error, Ruby};
480 ///
481 /// fn example(ruby: &Ruby) -> Result<(), Error> {
482 /// rb_assert!(
483 /// ruby,
484 /// "klass == Interrupt",
485 /// klass = ruby.exception_interrupt()
486 /// );
487 /// Ok(())
488 /// }
489 /// # Ruby::init(example).unwrap()
490 /// ```
491 #[inline]
492 pub fn exception_interrupt(&self) -> ExceptionClass {
493 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eInterrupt) }
494 }
495
496 /// Return Ruby's `KeyError` class.
497 ///
498 /// # Examples
499 ///
500 /// ```
501 /// use magnus::{rb_assert, Error, Ruby};
502 ///
503 /// fn example(ruby: &Ruby) -> Result<(), Error> {
504 /// rb_assert!(
505 /// ruby,
506 /// "klass == KeyError",
507 /// klass = ruby.exception_key_error()
508 /// );
509 /// Ok(())
510 /// }
511 /// # Ruby::init(example).unwrap()
512 /// ```
513 #[inline]
514 pub fn exception_key_error(&self) -> ExceptionClass {
515 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eKeyError) }
516 }
517
518 /// Return Ruby's `LoadError` class.
519 ///
520 /// # Examples
521 ///
522 /// ```
523 /// use magnus::{rb_assert, Error, Ruby};
524 ///
525 /// fn example(ruby: &Ruby) -> Result<(), Error> {
526 /// rb_assert!(
527 /// ruby,
528 /// "klass == LoadError",
529 /// klass = ruby.exception_load_error()
530 /// );
531 /// Ok(())
532 /// }
533 /// # Ruby::init(example).unwrap()
534 /// ```
535 #[inline]
536 pub fn exception_load_error(&self) -> ExceptionClass {
537 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eLoadError) }
538 }
539
540 /// Return Ruby's `LocalJumpError` class.
541 ///
542 /// # Examples
543 ///
544 /// ```
545 /// use magnus::{rb_assert, Error, Ruby};
546 ///
547 /// fn example(ruby: &Ruby) -> Result<(), Error> {
548 /// rb_assert!(
549 /// ruby,
550 /// "klass == LocalJumpError",
551 /// klass = ruby.exception_local_jump_error()
552 /// );
553 /// Ok(())
554 /// }
555 /// # Ruby::init(example).unwrap()
556 /// ```
557 #[inline]
558 pub fn exception_local_jump_error(&self) -> ExceptionClass {
559 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eLocalJumpError) }
560 }
561
562 /// Return Ruby's `Math::DomainError` class.
563 ///
564 /// # Examples
565 ///
566 /// ```
567 /// use magnus::{rb_assert, Error, Ruby};
568 ///
569 /// fn example(ruby: &Ruby) -> Result<(), Error> {
570 /// rb_assert!(
571 /// ruby,
572 /// "klass == Math::DomainError",
573 /// klass = ruby.exception_math_domain_error()
574 /// );
575 /// Ok(())
576 /// }
577 /// # Ruby::init(example).unwrap()
578 /// ```
579 #[inline]
580 pub fn exception_math_domain_error(&self) -> ExceptionClass {
581 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eMathDomainError) }
582 }
583
584 /// Return Ruby's `NameError` class.
585 ///
586 /// # Examples
587 ///
588 /// ```
589 /// use magnus::{rb_assert, Error, Ruby};
590 ///
591 /// fn example(ruby: &Ruby) -> Result<(), Error> {
592 /// rb_assert!(
593 /// ruby,
594 /// "klass == NameError",
595 /// klass = ruby.exception_name_error()
596 /// );
597 /// Ok(())
598 /// }
599 /// # Ruby::init(example).unwrap()
600 /// ```
601 #[inline]
602 pub fn exception_name_error(&self) -> ExceptionClass {
603 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eNameError) }
604 }
605
606 /// Return Ruby's `NoMatchingPatternError` class.
607 ///
608 /// # Examples
609 ///
610 /// ```
611 /// use magnus::{rb_assert, Error, Ruby};
612 ///
613 /// fn example(ruby: &Ruby) -> Result<(), Error> {
614 /// rb_assert!(
615 /// ruby,
616 /// "klass == NoMatchingPatternError",
617 /// klass = ruby.exception_no_matching_pattern_error()
618 /// );
619 /// Ok(())
620 /// }
621 /// # Ruby::init(example).unwrap()
622 /// ```
623 #[inline]
624 pub fn exception_no_matching_pattern_error(&self) -> ExceptionClass {
625 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eNoMatchingPatternError) }
626 }
627
628 /// Return Ruby's `NoMatchingPatternKeyError` class.
629 ///
630 /// # Examples
631 ///
632 /// ```
633 /// use magnus::{rb_assert, Error, Ruby};
634 ///
635 /// fn example(ruby: &Ruby) -> Result<(), Error> {
636 /// rb_assert!(
637 /// ruby,
638 /// "klass == NoMatchingPatternKeyError",
639 /// klass = ruby.exception_no_matching_pattern_key_error()
640 /// );
641 /// Ok(())
642 /// }
643 /// # Ruby::init(example).unwrap()
644 /// ```
645 #[cfg(any(ruby_gte_3_1, docsrs))]
646 #[cfg_attr(docsrs, doc(cfg(ruby_gte_3_1)))]
647 #[inline]
648 pub fn exception_no_matching_pattern_key_error(&self) -> ExceptionClass {
649 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eNoMatchingPatternKeyError) }
650 }
651
652 /// Return Ruby's `NoMemoryError` class.
653 ///
654 /// # Examples
655 ///
656 /// ```
657 /// use magnus::{rb_assert, Error, Ruby};
658 ///
659 /// fn example(ruby: &Ruby) -> Result<(), Error> {
660 /// rb_assert!(
661 /// ruby,
662 /// "klass == NoMemoryError",
663 /// klass = ruby.exception_no_mem_error()
664 /// );
665 /// Ok(())
666 /// }
667 /// # Ruby::init(example).unwrap()
668 /// ```
669 #[inline]
670 pub fn exception_no_mem_error(&self) -> ExceptionClass {
671 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eNoMemError) }
672 }
673
674 /// Return Ruby's `NoMethodError` class.
675 ///
676 /// # Examples
677 ///
678 /// ```
679 /// use magnus::{rb_assert, Error, Ruby};
680 ///
681 /// fn example(ruby: &Ruby) -> Result<(), Error> {
682 /// rb_assert!(
683 /// ruby,
684 /// "klass == NoMethodError",
685 /// klass = ruby.exception_no_method_error()
686 /// );
687 /// Ok(())
688 /// }
689 /// # Ruby::init(example).unwrap()
690 /// ```
691 #[inline]
692 pub fn exception_no_method_error(&self) -> ExceptionClass {
693 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eNoMethodError) }
694 }
695
696 /// Return Ruby's `NotImplementedError` class.
697 ///
698 /// # Examples
699 ///
700 /// ```
701 /// use magnus::{rb_assert, Error, Ruby};
702 ///
703 /// fn example(ruby: &Ruby) -> Result<(), Error> {
704 /// rb_assert!(
705 /// ruby,
706 /// "klass == NotImplementedError",
707 /// klass = ruby.exception_not_imp_error()
708 /// );
709 /// Ok(())
710 /// }
711 /// # Ruby::init(example).unwrap()
712 /// ```
713 #[inline]
714 pub fn exception_not_imp_error(&self) -> ExceptionClass {
715 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eNotImpError) }
716 }
717
718 /// Return Ruby's `RangeError` class.
719 ///
720 /// # Examples
721 ///
722 /// ```
723 /// use magnus::{rb_assert, Error, Ruby};
724 ///
725 /// fn example(ruby: &Ruby) -> Result<(), Error> {
726 /// rb_assert!(
727 /// ruby,
728 /// "klass == RangeError",
729 /// klass = ruby.exception_range_error()
730 /// );
731 /// Ok(())
732 /// }
733 /// # Ruby::init(example).unwrap()
734 /// ```
735 #[inline]
736 pub fn exception_range_error(&self) -> ExceptionClass {
737 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eRangeError) }
738 }
739
740 /// Return Ruby's `RegexpError` class.
741 ///
742 /// # Examples
743 ///
744 /// ```
745 /// use magnus::{rb_assert, Error, Ruby};
746 ///
747 /// fn example(ruby: &Ruby) -> Result<(), Error> {
748 /// rb_assert!(
749 /// ruby,
750 /// "klass == RegexpError",
751 /// klass = ruby.exception_regexp_error()
752 /// );
753 /// Ok(())
754 /// }
755 /// # Ruby::init(example).unwrap()
756 /// ```
757 #[inline]
758 pub fn exception_regexp_error(&self) -> ExceptionClass {
759 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eRegexpError) }
760 }
761
762 /// Return Ruby's `RuntimeError` class.
763 ///
764 /// # Examples
765 ///
766 /// ```
767 /// use magnus::{rb_assert, Error, Ruby};
768 ///
769 /// fn example(ruby: &Ruby) -> Result<(), Error> {
770 /// rb_assert!(
771 /// ruby,
772 /// "klass == RuntimeError",
773 /// klass = ruby.exception_runtime_error()
774 /// );
775 /// Ok(())
776 /// }
777 /// # Ruby::init(example).unwrap()
778 /// ```
779 #[inline]
780 pub fn exception_runtime_error(&self) -> ExceptionClass {
781 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eRuntimeError) }
782 }
783
784 /// Return Ruby's `ScriptError` class.
785 ///
786 /// # Examples
787 ///
788 /// ```
789 /// use magnus::{rb_assert, Error, Ruby};
790 ///
791 /// fn example(ruby: &Ruby) -> Result<(), Error> {
792 /// rb_assert!(
793 /// ruby,
794 /// "klass == ScriptError",
795 /// klass = ruby.exception_script_error()
796 /// );
797 /// Ok(())
798 /// }
799 /// # Ruby::init(example).unwrap()
800 /// ```
801 #[inline]
802 pub fn exception_script_error(&self) -> ExceptionClass {
803 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eScriptError) }
804 }
805
806 /// Return Ruby's `SecurityError` class.
807 ///
808 /// # Examples
809 ///
810 /// ```
811 /// use magnus::{rb_assert, Error, Ruby};
812 ///
813 /// fn example(ruby: &Ruby) -> Result<(), Error> {
814 /// rb_assert!(
815 /// ruby,
816 /// "klass == SecurityError",
817 /// klass = ruby.exception_security_error()
818 /// );
819 /// Ok(())
820 /// }
821 /// # Ruby::init(example).unwrap()
822 /// ```
823 #[inline]
824 pub fn exception_security_error(&self) -> ExceptionClass {
825 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eSecurityError) }
826 }
827
828 /// Return Ruby's `SignalException` class.
829 ///
830 /// # Examples
831 ///
832 /// ```
833 /// use magnus::{rb_assert, Error, Ruby};
834 ///
835 /// fn example(ruby: &Ruby) -> Result<(), Error> {
836 /// rb_assert!(
837 /// ruby,
838 /// "klass == SignalException",
839 /// klass = ruby.exception_signal()
840 /// );
841 /// Ok(())
842 /// }
843 /// # Ruby::init(example).unwrap()
844 /// ```
845 #[inline]
846 pub fn exception_signal(&self) -> ExceptionClass {
847 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eSignal) }
848 }
849
850 /// Return Ruby's `StandardError` class.
851 ///
852 /// # Examples
853 ///
854 /// ```
855 /// use magnus::{rb_assert, Error, Ruby};
856 ///
857 /// fn example(ruby: &Ruby) -> Result<(), Error> {
858 /// rb_assert!(
859 /// ruby,
860 /// "klass == StandardError",
861 /// klass = ruby.exception_standard_error()
862 /// );
863 /// Ok(())
864 /// }
865 /// # Ruby::init(example).unwrap()
866 /// ```
867 #[inline]
868 pub fn exception_standard_error(&self) -> ExceptionClass {
869 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eStandardError) }
870 }
871
872 /// Return Ruby's `StopIteration` class.
873 ///
874 /// # Examples
875 ///
876 /// ```
877 /// use magnus::{rb_assert, Error, Ruby};
878 ///
879 /// fn example(ruby: &Ruby) -> Result<(), Error> {
880 /// rb_assert!(
881 /// ruby,
882 /// "klass == StopIteration",
883 /// klass = ruby.exception_stop_iteration()
884 /// );
885 /// Ok(())
886 /// }
887 /// # Ruby::init(example).unwrap()
888 /// ```
889 #[inline]
890 pub fn exception_stop_iteration(&self) -> ExceptionClass {
891 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eStopIteration) }
892 }
893
894 /// Return Ruby's `SyntaxError` class.
895 ///
896 /// # Examples
897 ///
898 /// ```
899 /// use magnus::{rb_assert, Error, Ruby};
900 ///
901 /// fn example(ruby: &Ruby) -> Result<(), Error> {
902 /// rb_assert!(
903 /// ruby,
904 /// "klass == SyntaxError",
905 /// klass = ruby.exception_syntax_error()
906 /// );
907 /// Ok(())
908 /// }
909 /// # Ruby::init(example).unwrap()
910 /// ```
911 #[inline]
912 pub fn exception_syntax_error(&self) -> ExceptionClass {
913 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eSyntaxError) }
914 }
915
916 /// Return Ruby's `SystemStackError` class.
917 ///
918 /// # Examples
919 ///
920 /// ```
921 /// use magnus::{rb_assert, Error, Ruby};
922 ///
923 /// fn example(ruby: &Ruby) -> Result<(), Error> {
924 /// rb_assert!(
925 /// ruby,
926 /// "klass == SystemStackError",
927 /// klass = ruby.exception_sys_stack_error()
928 /// );
929 /// Ok(())
930 /// }
931 /// # Ruby::init(example).unwrap()
932 /// ```
933 #[inline]
934 pub fn exception_sys_stack_error(&self) -> ExceptionClass {
935 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eSysStackError) }
936 }
937
938 /// Return Ruby's `SystemCallError` class.
939 ///
940 /// # Examples
941 ///
942 /// ```
943 /// use magnus::{rb_assert, Error, Ruby};
944 ///
945 /// fn example(ruby: &Ruby) -> Result<(), Error> {
946 /// rb_assert!(
947 /// ruby,
948 /// "klass == SystemCallError",
949 /// klass = ruby.exception_system_call_error()
950 /// );
951 /// Ok(())
952 /// }
953 /// # Ruby::init(example).unwrap()
954 /// ```
955 #[inline]
956 pub fn exception_system_call_error(&self) -> ExceptionClass {
957 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eSystemCallError) }
958 }
959
960 /// Return Ruby's `SystemExit` class.
961 ///
962 /// # Examples
963 ///
964 /// ```
965 /// use magnus::{rb_assert, Error, Ruby};
966 ///
967 /// fn example(ruby: &Ruby) -> Result<(), Error> {
968 /// rb_assert!(
969 /// ruby,
970 /// "klass == SystemExit",
971 /// klass = ruby.exception_system_exit()
972 /// );
973 /// Ok(())
974 /// }
975 /// # Ruby::init(example).unwrap()
976 /// ```
977 #[inline]
978 pub fn exception_system_exit(&self) -> ExceptionClass {
979 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eSystemExit) }
980 }
981
982 /// Return Ruby's `ThreadError` class.
983 ///
984 /// # Examples
985 ///
986 /// ```
987 /// use magnus::{rb_assert, Error, Ruby};
988 ///
989 /// fn example(ruby: &Ruby) -> Result<(), Error> {
990 /// rb_assert!(
991 /// ruby,
992 /// "klass == ThreadError",
993 /// klass = ruby.exception_thread_error()
994 /// );
995 /// Ok(())
996 /// }
997 /// # Ruby::init(example).unwrap()
998 /// ```
999 #[inline]
1000 pub fn exception_thread_error(&self) -> ExceptionClass {
1001 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eThreadError) }
1002 }
1003
1004 /// Return Ruby's `TypeError` class.
1005 ///
1006 /// # Examples
1007 ///
1008 /// ```
1009 /// use magnus::{rb_assert, Error, Ruby};
1010 ///
1011 /// fn example(ruby: &Ruby) -> Result<(), Error> {
1012 /// rb_assert!(
1013 /// ruby,
1014 /// "klass == TypeError",
1015 /// klass = ruby.exception_type_error()
1016 /// );
1017 /// Ok(())
1018 /// }
1019 /// # Ruby::init(example).unwrap()
1020 /// ```
1021 #[inline]
1022 pub fn exception_type_error(&self) -> ExceptionClass {
1023 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eTypeError) }
1024 }
1025
1026 /// Return Ruby's `ZeroDivisionError` class.
1027 ///
1028 /// # Examples
1029 ///
1030 /// ```
1031 /// use magnus::{rb_assert, Error, Ruby};
1032 ///
1033 /// fn example(ruby: &Ruby) -> Result<(), Error> {
1034 /// rb_assert!(
1035 /// ruby,
1036 /// "klass == ZeroDivisionError",
1037 /// klass = ruby.exception_zero_div_error()
1038 /// );
1039 /// Ok(())
1040 /// }
1041 /// # Ruby::init(example).unwrap()
1042 /// ```
1043 #[inline]
1044 pub fn exception_zero_div_error(&self) -> ExceptionClass {
1045 unsafe { ExceptionClass::from_rb_value_unchecked(rb_eZeroDivError) }
1046 }
1047}
1048
1049/// Return Ruby's `ArgumentError` class.
1050///
1051/// # Panics
1052///
1053/// Panics if called from a non-Ruby thread. See [`Ruby::exception_arg_error`]
1054/// for the non-panicking version.
1055#[cfg_attr(
1056 not(feature = "old-api"),
1057 deprecated(note = "please use `Ruby::exception_arg_error` instead")
1058)]
1059#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1060#[inline]
1061pub fn arg_error() -> ExceptionClass {
1062 get_ruby!().exception_arg_error()
1063}
1064
1065/// Return Ruby's `EOFError` class.
1066///
1067/// # Panics
1068///
1069/// Panics if called from a non-Ruby thread. See [`Ruby::exception_eof_error`]
1070/// for the non-panicking version.
1071#[cfg_attr(
1072 not(feature = "old-api"),
1073 deprecated(note = "please use `Ruby::exception_eof_error` instead")
1074)]
1075#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1076#[inline]
1077pub fn eof_error() -> ExceptionClass {
1078 get_ruby!().exception_eof_error()
1079}
1080
1081/// Return Ruby's `Encoding::CompatibilityError` class.
1082///
1083/// # Panics
1084///
1085/// Panics if called from a non-Ruby thread. See
1086/// [`Ruby::exception_enc_compat_error`] for the non-panicking version.
1087#[cfg_attr(
1088 not(feature = "old-api"),
1089 deprecated(note = "please use `Ruby::exception_enc_compat_error` instead")
1090)]
1091#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1092#[inline]
1093pub fn enc_compat_error() -> ExceptionClass {
1094 get_ruby!().exception_enc_compat_error()
1095}
1096
1097/// Return Ruby's `EncodingError` class.
1098///
1099/// # Panics
1100///
1101/// Panics if called from a non-Ruby thread. See
1102/// [`Ruby::exception_encoding_error`] for the non-panicking version.
1103#[cfg_attr(
1104 not(feature = "old-api"),
1105 deprecated(note = "please use `Ruby::exception_encoding_error` instead")
1106)]
1107#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1108#[inline]
1109pub fn encoding_error() -> ExceptionClass {
1110 get_ruby!().exception_encoding_error()
1111}
1112
1113/// Return Ruby's `Exception` class.
1114///
1115/// # Panics
1116///
1117/// Panics if called from a non-Ruby thread. See [`Ruby::exception_exception`]
1118/// for the non-panicking version.
1119#[cfg_attr(
1120 not(feature = "old-api"),
1121 deprecated(note = "please use `Ruby::exception_exception` instead")
1122)]
1123#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1124#[inline]
1125pub fn exception() -> ExceptionClass {
1126 get_ruby!().exception_exception()
1127}
1128
1129/// Return Ruby's `fatal` class.
1130///
1131/// # Panics
1132///
1133/// Panics if called from a non-Ruby thread. See [`Ruby::exception_fatal`] for
1134/// the non-panicking version.
1135#[cfg_attr(
1136 not(feature = "old-api"),
1137 deprecated(note = "please use `Ruby::exception_fatal` instead")
1138)]
1139#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1140#[inline]
1141pub fn fatal() -> ExceptionClass {
1142 get_ruby!().exception_fatal()
1143}
1144
1145/// Return Ruby's `FloatDomainError` class.
1146///
1147/// # Panics
1148///
1149/// Panics if called from a non-Ruby thread. See
1150/// [`Ruby::exception_float_domain_error`] for the non-panicking version.
1151#[cfg_attr(
1152 not(feature = "old-api"),
1153 deprecated(note = "please use `Ruby::exception_float_domain_error` instead")
1154)]
1155#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1156#[inline]
1157pub fn float_domain_error() -> ExceptionClass {
1158 get_ruby!().exception_float_domain_error()
1159}
1160
1161/// Return Ruby's `FrozenError` class.
1162///
1163/// # Panics
1164///
1165/// Panics if called from a non-Ruby thread. See
1166/// [`Ruby::exception_frozen_error`] for the non-panicking version.
1167#[cfg_attr(
1168 not(feature = "old-api"),
1169 deprecated(note = "please use `Ruby::exception_frozen_error` instead")
1170)]
1171#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1172#[inline]
1173pub fn frozen_error() -> ExceptionClass {
1174 get_ruby!().exception_frozen_error()
1175}
1176
1177/// Return Ruby's `IOError` class.
1178///
1179/// # Panics
1180///
1181/// Panics if called from a non-Ruby thread. See [`Ruby::exception_io_error`]
1182/// for the non-panicking version.
1183#[cfg_attr(
1184 not(feature = "old-api"),
1185 deprecated(note = "please use `Ruby::exception_io_error` instead")
1186)]
1187#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1188#[inline]
1189pub fn io_error() -> ExceptionClass {
1190 get_ruby!().exception_io_error()
1191}
1192
1193/// Return Ruby's `IndexError` class.
1194///
1195/// # Panics
1196///
1197/// Panics if called from a non-Ruby thread. See
1198/// [`Ruby::exception_index_error`] for the non-panicking version.
1199#[cfg_attr(
1200 not(feature = "old-api"),
1201 deprecated(note = "please use `Ruby::exception_index_error` instead")
1202)]
1203#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1204#[inline]
1205pub fn index_error() -> ExceptionClass {
1206 get_ruby!().exception_index_error()
1207}
1208
1209/// Return Ruby's `Interrupt` class.
1210///
1211/// # Panics
1212///
1213/// Panics if called from a non-Ruby thread. See [`Ruby::exception_interrupt`]
1214/// for the non-panicking version.
1215#[cfg_attr(
1216 not(feature = "old-api"),
1217 deprecated(note = "please use `Ruby::exception_interrupt` instead")
1218)]
1219#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1220#[inline]
1221pub fn interrupt() -> ExceptionClass {
1222 get_ruby!().exception_interrupt()
1223}
1224
1225/// Return Ruby's `KeyError` class.
1226///
1227/// # Panics
1228///
1229/// Panics if called from a non-Ruby thread. See [`Ruby::exception_key_error`]
1230/// for the non-panicking version.
1231#[cfg_attr(
1232 not(feature = "old-api"),
1233 deprecated(note = "please use `Ruby::exception_key_error` instead")
1234)]
1235#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1236#[inline]
1237pub fn key_error() -> ExceptionClass {
1238 get_ruby!().exception_key_error()
1239}
1240
1241/// Return Ruby's `LoadError` class.
1242///
1243/// # Panics
1244///
1245/// Panics if called from a non-Ruby thread. See [`Ruby::exception_load_error`]
1246/// for the non-panicking version.
1247#[cfg_attr(
1248 not(feature = "old-api"),
1249 deprecated(note = "please use `Ruby::exception_load_error` instead")
1250)]
1251#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1252#[inline]
1253pub fn load_error() -> ExceptionClass {
1254 get_ruby!().exception_load_error()
1255}
1256
1257/// Return Ruby's `LocalJumpError` class.
1258///
1259/// # Panics
1260///
1261/// Panics if called from a non-Ruby thread. See
1262/// [`Ruby::exception_local_jump_error`] for the non-panicking version.
1263#[cfg_attr(
1264 not(feature = "old-api"),
1265 deprecated(note = "please use `Ruby::exception_local_jump_error` instead")
1266)]
1267#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1268#[inline]
1269pub fn local_jump_error() -> ExceptionClass {
1270 get_ruby!().exception_local_jump_error()
1271}
1272
1273/// Return Ruby's `Math::DomainError` class.
1274///
1275/// # Panics
1276///
1277/// Panics if called from a non-Ruby thread. See
1278/// [`Ruby::exception_math_domain_error`] for the non-panicking version.
1279#[cfg_attr(
1280 not(feature = "old-api"),
1281 deprecated(note = "please use `Ruby::exception_math_domain_error` instead")
1282)]
1283#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1284#[inline]
1285pub fn math_domain_error() -> ExceptionClass {
1286 get_ruby!().exception_math_domain_error()
1287}
1288
1289/// Return Ruby's `NameError` class.
1290///
1291/// # Panics
1292///
1293/// Panics if called from a non-Ruby thread. See
1294/// [`Ruby::exception_name_error`] for the non-panicking version.
1295#[cfg_attr(
1296 not(feature = "old-api"),
1297 deprecated(note = "please use `Ruby::exception_name_error` instead")
1298)]
1299#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1300#[inline]
1301pub fn name_error() -> ExceptionClass {
1302 get_ruby!().exception_name_error()
1303}
1304
1305/// Return Ruby's `NoMatchingPatternError` class.
1306///
1307/// # Panics
1308///
1309/// Panics if called from a non-Ruby thread. See
1310/// [`Ruby::exception_no_matching_pattern_error`] for the non-panicking version.
1311#[cfg_attr(
1312 not(feature = "old-api"),
1313 deprecated(note = "please use `Ruby::exception_no_matching_pattern_error` instead")
1314)]
1315#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1316#[inline]
1317pub fn no_matching_pattern_error() -> ExceptionClass {
1318 get_ruby!().exception_no_matching_pattern_error()
1319}
1320
1321/// Return Ruby's `NoMatchingPatternKeyError` class.
1322///
1323/// # Panics
1324///
1325/// Panics if called from a non-Ruby thread. See
1326/// [`Ruby::exception_no_matching_pattern_key_error`] for the non-panicking
1327/// version.
1328#[cfg(any(ruby_gte_3_1, docsrs))]
1329#[cfg_attr(docsrs, doc(cfg(ruby_gte_3_1)))]
1330#[cfg_attr(
1331 not(feature = "old-api"),
1332 deprecated(note = "please use `Ruby::exception_no_matching_pattern_key_error` instead")
1333)]
1334#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1335#[inline]
1336pub fn no_matching_pattern_key_error() -> ExceptionClass {
1337 get_ruby!().exception_no_matching_pattern_key_error()
1338}
1339
1340/// Return Ruby's `NoMemoryError` class.
1341///
1342/// # Panics
1343///
1344/// Panics if called from a non-Ruby thread. See
1345/// [`Ruby::exception_no_mem_error`] for the non-panicking version.
1346#[cfg_attr(
1347 not(feature = "old-api"),
1348 deprecated(note = "please use `Ruby::exception_no_mem_error` instead")
1349)]
1350#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1351#[inline]
1352pub fn no_mem_error() -> ExceptionClass {
1353 get_ruby!().exception_no_mem_error()
1354}
1355
1356/// Return Ruby's `NoMethodError` class.
1357///
1358/// # Panics
1359///
1360/// Panics if called from a non-Ruby thread. See
1361/// [`Ruby::exception_no_method_error`] for the non-panicking version.
1362#[cfg_attr(
1363 not(feature = "old-api"),
1364 deprecated(note = "please use `Ruby::exception_no_method_error` instead")
1365)]
1366#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1367#[inline]
1368pub fn no_method_error() -> ExceptionClass {
1369 get_ruby!().exception_no_method_error()
1370}
1371
1372/// Return Ruby's `NotImplementedError` class.
1373///
1374/// # Panics
1375///
1376/// Panics if called from a non-Ruby thread. See
1377/// [`Ruby::exception_not_imp_error`] for the non-panicking version.
1378#[cfg_attr(
1379 not(feature = "old-api"),
1380 deprecated(note = "please use `Ruby::exception_not_imp_error` instead")
1381)]
1382#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1383#[inline]
1384pub fn not_imp_error() -> ExceptionClass {
1385 get_ruby!().exception_not_imp_error()
1386}
1387
1388/// Return Ruby's `RangeError` class.
1389///
1390/// # Panics
1391///
1392/// Panics if called from a non-Ruby thread. See
1393/// [`Ruby::exception_range_error`] for the non-panicking version.
1394#[cfg_attr(
1395 not(feature = "old-api"),
1396 deprecated(note = "please use `Ruby::exception_range_error` instead")
1397)]
1398#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1399#[inline]
1400pub fn range_error() -> ExceptionClass {
1401 get_ruby!().exception_range_error()
1402}
1403
1404/// Return Ruby's `RegexpError` class.
1405///
1406/// # Panics
1407///
1408/// Panics if called from a non-Ruby thread. See
1409/// [`Ruby::exception_regexp_error`] for the non-panicking version.
1410#[cfg_attr(
1411 not(feature = "old-api"),
1412 deprecated(note = "please use `Ruby::exception_regexp_error` instead")
1413)]
1414#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1415#[inline]
1416pub fn regexp_error() -> ExceptionClass {
1417 get_ruby!().exception_regexp_error()
1418}
1419
1420/// Return Ruby's `RuntimeError` class.
1421///
1422/// # Panics
1423///
1424/// Panics if called from a non-Ruby thread. See
1425/// [`Ruby::exception_runtime_error`] for the non-panicking version.
1426#[cfg_attr(
1427 not(feature = "old-api"),
1428 deprecated(note = "please use `Ruby::exception_runtime_error` instead")
1429)]
1430#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1431#[inline]
1432pub fn runtime_error() -> ExceptionClass {
1433 get_ruby!().exception_runtime_error()
1434}
1435
1436/// Return Ruby's `ScriptError` class.
1437///
1438/// # Panics
1439///
1440/// Panics if called from a non-Ruby thread. See
1441/// [`Ruby::exception_script_error`] for the non-panicking version.
1442#[cfg_attr(
1443 not(feature = "old-api"),
1444 deprecated(note = "please use `Ruby::exception_script_error` instead")
1445)]
1446#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1447#[inline]
1448pub fn script_error() -> ExceptionClass {
1449 get_ruby!().exception_script_error()
1450}
1451
1452/// Return Ruby's `SecurityError` class.
1453///
1454/// # Panics
1455///
1456/// Panics if called from a non-Ruby thread. See
1457/// [`Ruby::exception_security_error`] for the non-panicking version.
1458#[cfg_attr(
1459 not(feature = "old-api"),
1460 deprecated(note = "please use `Ruby::exception_security_error` instead")
1461)]
1462#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1463#[inline]
1464pub fn security_error() -> ExceptionClass {
1465 get_ruby!().exception_security_error()
1466}
1467
1468/// Return Ruby's `SignalException` class.
1469///
1470/// # Panics
1471///
1472/// Panics if called from a non-Ruby thread. See
1473/// [`Ruby::exception_signal`] for the non-panicking version.
1474#[cfg_attr(
1475 not(feature = "old-api"),
1476 deprecated(note = "please use `Ruby::exception_signal` instead")
1477)]
1478#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1479#[inline]
1480pub fn signal() -> ExceptionClass {
1481 get_ruby!().exception_signal()
1482}
1483
1484/// Return Ruby's `StandardError` class.
1485///
1486/// # Panics
1487///
1488/// Panics if called from a non-Ruby thread. See
1489/// [`Ruby::exception_standard_error`] for the non-panicking version.
1490#[cfg_attr(
1491 not(feature = "old-api"),
1492 deprecated(note = "please use `Ruby::exception_standard_error` instead")
1493)]
1494#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1495#[inline]
1496pub fn standard_error() -> ExceptionClass {
1497 get_ruby!().exception_standard_error()
1498}
1499
1500/// Return Ruby's `StopIteration` class.
1501///
1502/// # Panics
1503///
1504/// Panics if called from a non-Ruby thread. See
1505/// [`Ruby::exception_stop_iteration`] for the non-panicking version.
1506#[cfg_attr(
1507 not(feature = "old-api"),
1508 deprecated(note = "please use `Ruby::exception_stop_iteration` instead")
1509)]
1510#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1511#[inline]
1512pub fn stop_iteration() -> ExceptionClass {
1513 get_ruby!().exception_stop_iteration()
1514}
1515
1516/// Return Ruby's `SyntaxError` class.
1517///
1518/// # Panics
1519///
1520/// Panics if called from a non-Ruby thread. See
1521/// [`Ruby::exception_syntax_error`] for the non-panicking version.
1522#[cfg_attr(
1523 not(feature = "old-api"),
1524 deprecated(note = "please use `Ruby::exception_syntax_error` instead")
1525)]
1526#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1527#[inline]
1528pub fn syntax_error() -> ExceptionClass {
1529 get_ruby!().exception_syntax_error()
1530}
1531
1532/// Return Ruby's `SystemStackError` class.
1533///
1534/// # Panics
1535///
1536/// Panics if called from a non-Ruby thread. See
1537/// [`Ruby::exception_sys_stack_error`] for the non-panicking version.
1538#[cfg_attr(
1539 not(feature = "old-api"),
1540 deprecated(note = "please use `Ruby::exception_sys_stack_error` instead")
1541)]
1542#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1543#[inline]
1544pub fn sys_stack_error() -> ExceptionClass {
1545 get_ruby!().exception_sys_stack_error()
1546}
1547
1548/// Return Ruby's `SystemCallError` class.
1549///
1550/// # Panics
1551///
1552/// Panics if called from a non-Ruby thread. See
1553/// [`Ruby::exception_system_call_error`] for the non-panicking version.
1554#[cfg_attr(
1555 not(feature = "old-api"),
1556 deprecated(note = "please use `Ruby::exception_system_call_error` instead")
1557)]
1558#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1559#[inline]
1560pub fn system_call_error() -> ExceptionClass {
1561 get_ruby!().exception_system_call_error()
1562}
1563
1564/// Return Ruby's `SystemExit` class.
1565///
1566/// # Panics
1567///
1568/// Panics if called from a non-Ruby thread. See
1569/// [`Ruby::exception_system_exit`] for the non-panicking version.
1570#[cfg_attr(
1571 not(feature = "old-api"),
1572 deprecated(note = "please use `Ruby::exception_system_exit` instead")
1573)]
1574#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1575#[inline]
1576pub fn system_exit() -> ExceptionClass {
1577 get_ruby!().exception_system_exit()
1578}
1579
1580/// Return Ruby's `ThreadError` class.
1581///
1582/// # Panics
1583///
1584/// Panics if called from a non-Ruby thread. See
1585/// [`Ruby::exception_thread_error`] for the non-panicking version.
1586#[cfg_attr(
1587 not(feature = "old-api"),
1588 deprecated(note = "please use `Ruby::exception_thread_error` instead")
1589)]
1590#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1591#[inline]
1592pub fn thread_error() -> ExceptionClass {
1593 get_ruby!().exception_thread_error()
1594}
1595
1596/// Return Ruby's `TypeError` class.
1597///
1598/// # Panics
1599///
1600/// Panics if called from a non-Ruby thread. See [`Ruby::exception_type_error`]
1601/// for the non-panicking version.
1602#[cfg_attr(
1603 not(feature = "old-api"),
1604 deprecated(note = "please use `Ruby::exception_type_error` instead")
1605)]
1606#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1607#[inline]
1608pub fn type_error() -> ExceptionClass {
1609 get_ruby!().exception_type_error()
1610}
1611
1612/// Return Ruby's `ZeroDivisionError` class.
1613///
1614/// # Panics
1615///
1616/// Panics if called from a non-Ruby thread. See
1617/// [`Ruby::exception_zero_div_error`] for the non-panicking version.
1618#[cfg_attr(
1619 not(feature = "old-api"),
1620 deprecated(note = "please use `Ruby::exception_zero_div_error` instead")
1621)]
1622#[cfg_attr(docsrs, doc(cfg(feature = "old-api")))]
1623#[inline]
1624pub fn zero_div_error() -> ExceptionClass {
1625 get_ruby!().exception_zero_div_error()
1626}