Exception: Exception
- Defined in:
- opal/opal/corelib/error.rb
Direct Known Subclasses
Enumerator::Lazy::StopLazyError , Interrupt , NoMemoryError , ScriptError , SecurityError , SignalException , StandardError , SystemExit
Class Method Summary collapse
Instance Method Summary collapse
- #backtrace ⇒ Object
- #exception(str = nil) ⇒ Object
-
#initialize(*args) ⇒ Exception
constructor
A new instance of Exception.
- #inspect ⇒ Object
-
#message ⇒ Object
not using alias message to_s because you need to be able to override to_s and have message use overridden method, won't work with alias.
- #set_backtrace(backtrace) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Exception
Returns a new instance of Exception.
31 32 33 34
# File 'opal/opal/corelib/error.rb', line 31 def initialize(*args) # using self.message aka @message to retain compatibility with native exception's message property `self.message = (args.length > 0) ? args[0] : nil` end
Class Method Details
.exception(*args) ⇒ Object
27 28 29
# File 'opal/opal/corelib/error.rb', line 27 def self.exception(*args) new(*args) end
.new(*args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# File 'opal/opal/corelib/error.rb', line 5 def self.new(*args) %x{ var message = (args.length > 0) ? args[0] : nil; var error = new self.$$constructor(message); error.name = self.$$name; error.message = message; Opal.send(error, error.$initialize, args); // Error.captureStackTrace() will use .name and .toString to build the // first line of the stack trace so it must be called after the error // has been initialized. // https://nodejs.org/dist/latest-v6.x/docs/api/errors.html if (Opal.config.enable_stack_trace && Error.captureStackTrace) { // Passing Kernel.raise will cut the stack trace from that point above Error.captureStackTrace(error, stack_trace_limit); } return error; } end
Instance Method Details
#backtrace ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
# File 'opal/opal/corelib/error.rb', line 36 def backtrace %x{ if (self.backtrace) { // nil is a valid backtrace return self.backtrace; } var backtrace = self.stack; if (typeof(backtrace) === 'string') { return backtrace.split("\n").slice(0, 15); } else if (backtrace) { return backtrace.slice(0, 15); } return []; } end
#exception(str = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67
# File 'opal/opal/corelib/error.rb', line 56 def exception(str = nil) %x{ if (str === nil || self === str) { return self; } var cloned = #{clone}; cloned.message = str; cloned.stack = self.stack; return cloned; } end
#inspect ⇒ Object
#message ⇒ Object
not using alias message to_s because you need to be able to override to_s and have message use overridden method, won't work with alias
70 71 72
# File 'opal/opal/corelib/error.rb', line 70 def message to_s end
#set_backtrace(backtrace) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
# File 'opal/opal/corelib/error.rb', line 79 def set_backtrace(backtrace) %x{ var valid = true, i, ii; if (backtrace === nil) { self.backtrace = nil; self.stack = ''; } else if (backtrace.$$is_string) { self.backtrace = [backtrace]; self.stack = backtrace; } else { if (backtrace.$$is_array) { for (i = 0, ii = backtrace.length; i < ii; i++) { if (!backtrace[i].$$is_string) { valid = false; break; } } } else { valid = false; } if (valid === false) { #{raise TypeError , 'backtrace must be Array of String'} } self.backtrace = backtrace; self.stack = backtrace.join('\n'); } return backtrace; } end