Sha256: b84ae33b99957b9962fcbb6a0ee54f8489fd3dbbd3ca1e9a7a0eee15a32805f5

Contents?: true

Size: 1.85 KB

Versions: 11

Compression:

Stored size: 1.85 KB

Contents

class Exception
  attr_reader :message

  def self.new(message = 'Exception')
    %x{
      var err = new self.$$alloc(message);

      if (Error.captureStackTrace) {
        Error.captureStackTrace(err);
      }

      err.name = self.$$name;
      err.$initialize(message);
      return err;
    }
  end

  def initialize(message)
    `self.message = message`
  end

  def backtrace
    %x{
      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

  def inspect
    "#<#{self.class}: '#@message'>"
  end

  alias to_s message
end

# keep the indentation, it makes the exception hierarchy clear
class ScriptError       < Exception; end
class SyntaxError         < ScriptError; end
class LoadError           < ScriptError; end
class NotImplementedError < ScriptError; end

class SystemExit        < Exception; end
class NoMemoryError     < Exception; end
class SignalException   < Exception; end
class Interrupt         < Exception; end

class StandardError     < Exception; end
class NameError           < StandardError; end
class NoMethodError         < NameError; end
class RuntimeError        < StandardError; end
class LocalJumpError      < StandardError; end
class TypeError           < StandardError; end
class ArgumentError       < StandardError; end
class IndexError          < StandardError; end
class StopIteration         < IndexError; end
class KeyError              < IndexError; end
class RangeError          < StandardError; end
class FloatDomainError      < RangeError; end
class IOError             < StandardError; end
class SystemCallError     < StandardError; end
module Errno
  class EINVAL              < SystemCallError
    def self.new
      super('Invalid argument')
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
opal-0.8.1 opal/corelib/error.rb
opal-0.8.1.rc1 opal/corelib/error.rb
opal-0.8.0 opal/corelib/error.rb
opal-0.8.0.rc3 opal/corelib/error.rb
opal-0.8.0.rc2 opal/corelib/error.rb
opal-0.8.0.rc1 opal/corelib/error.rb
opal-0.8.0.beta1 opal/corelib/error.rb
opal-0.7.2 opal/corelib/error.rb
opal-0.7.1 opal/corelib/error.rb
opal-0.7.0 opal/corelib/error.rb
opal-0.7.0.rc1 opal/corelib/error.rb