D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Kernel
/
Filename :
raise-i.ri
back
Copy
U:RDoc::AnyMethod[iI" raise:ETI"Kernel#raise;TF:publico:RDoc::Markup::Document:@parts[*o:RDoc::Markup::Paragraph; [I"Raises an exception; ;TI".see {Exceptions}[rdoc-ref:exceptions.md].;To:RDoc::Markup::BlankLine o; ; [ I"?Argument +exception+ sets the class of the new exception; ;TI";it should be class Exception or one of its subclasses ;TI"5(most commonly, RuntimeError or StandardError), ;TI",or an instance of one of those classes:;T@o:RDoc::Markup::Verbatim; [I"begin ;TI" raise(StandardError) ;TI"rescue => x ;TI" p x.class ;TI" end ;TI"# => StandardError ;T:@format0o; ; [ I"FArgument +message+ sets the stored message in the new exception, ;TI"9which may be retrieved by method Exception#message; ;TI"the message must be ;TI"aa {string-convertible object}[rdoc-ref:implicit_conversion.rdoc@String-Convertible+Objects] ;TI"or +nil+:;T@o;; [I"begin ;TI"$ raise(StandardError, 'Boom') ;TI"rescue => x ;TI" p x.message ;TI" end ;TI"# => "Boom" ;T; 0o; ; [I")If argument +message+ is not given, ;TI"-the message is the exception class name.;T@o; ; [I"5See {Messages}[rdoc-ref:exceptions.md@Messages].;T@o; ; [ I"VArgument +backtrace+ might be used to modify the backtrace of the new exception, ;TI"Kas reported by Exception#backtrace and Exception#backtrace_locations; ;TI"Pthe backtrace must be an array of Thread::Backtrace::Location, an array of ;TI"(strings, a single string, or +nil+.;T@o; ; [ I"\Using the array of Thread::Backtrace::Location instances is the most consistent option ;TI"Rand should be preferred when possible. The necessary value might be obtained ;TI"Ufrom #caller_locations, or copied from Exception#backtrace_locations of another ;TI"error:;T@o;; [ I"begin ;TI" do_some_work() ;TI"$rescue ZeroDivisionError => ex ;TI"U raise(LogicalError, "You have an error in your math", ex.backtrace_locations) ;TI" end ;T; 0o; ; [I"QThe ways, both Exception#backtrace and Exception#backtrace_locations of the ;TI"0raised error are set to the same backtrace.;T@o; ; [I"EWhen the desired stack of locations is not available and should ;TI"Dbe constructed from scratch, an array of strings or a singular ;TI"Gstring can be used. In this case, only Exception#backtrace is set:;T@o;; [ I"begin ;TI"A raise(StandardError, 'Boom', %w[dsl.rb:3 framework.rb:1]) ;TI"rescue => ex ;TI" p ex.backtrace ;TI"+ # => ["dsl.rb:3", "framework.rb:1"] ;TI" p ex.backtrace_locations ;TI" # => nil ;TI" end ;T; 0o; ; [I"+If argument +backtrace+ is not given, ;TI"Xthe backtrace is set according to an array of Thread::Backtrace::Location objects, ;TI"$as derived from the call stack.;T@o; ; [I"9See {Backtraces}[rdoc-ref:exceptions.md@Backtraces].;T@o; ; [ I"JKeyword argument +cause+ sets the stored cause in the new exception, ;TI"7which may be retrieved by method Exception#cause; ;TI"Qthe cause must be an exception object (Exception or one of its subclasses), ;TI"or +nil+:;T@o;; [I"begin ;TI"5 raise(StandardError, cause: RuntimeError.new) ;TI"rescue => x ;TI" p x.cause ;TI" end ;TI"(# => #<RuntimeError: RuntimeError> ;T; 0o; ; [I"/If keyword argument +cause+ is not given, ;TI"+the cause is the value of <tt>$!</tt>.;T@o; ; [I"/See {Cause}[rdoc-ref:exceptions.md@Cause].;T@o; ; [ I"(In the alternate calling sequence, ;TI"-where argument +exception+ _not_ given, ;TI"?raises a new exception of the class given by <tt>$!</tt>, ;TI"6or of class RuntimeError if <tt>$!</tt> is +nil+:;T@o;; [I"begin ;TI" raise ;TI"rescue => x ;TI" p x ;TI" end ;TI"# => RuntimeError ;T; 0o; ; [I"*With argument +exception+ not given, ;TI"Cargument +message+ and keyword argument +cause+ may be given, ;TI"/but argument +backtrace+ may not be given.;T: @fileI"eval.c;T:0@omit_headings_from_table_of_contents_below0I"lraise(exception, message = exception.to_s, backtrace = nil, cause: $!) raise(message = nil, cause: $!) ;T0[[I" fail;T@ I"(*args);T@�FI"Kernel;TcRDoc::NormalModule00