File: common/exception.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#8
  module: Exception#10
  module: Abstraction#12
  class: Abstract#14
inherits from
  StandardError ( Builtin-Module )
  class: Expected#18
inherits from
  Abstract ( Umu::Exception::Abstraction )
has properties
attribute: msg [R] #19
method: initialize / 2 #22
method: to_s #29
method: __category__ #36
  class: ExecutionError#43
inherits from
  Expected ( Umu::Exception::Abstraction )
has properties
attribute: loc [R] #44
method: initialize / 3 #47
method: to_s #56
  class: RuntimeError#63
inherits from
  ExecutionError ( Umu::Exception::Abstraction )
has properties
attribute: env [R] #64
method: initialize / 4 #67
method: print_backtrace #77
  class: SubclassResponsibility#84
  class: CommandError#90
inherits from
  Expected ( Umu::Exception::Abstraction )
  class: SyntaxErrorWithoutLocation#92
inherits from
  Expected ( Umu::Exception::Abstraction )
has properties
method: __category__ #96
  class: LexicalError#103
  class: SyntaxError#104
  class: NameError#108
  class: TypeError#109
  class: ValueError#110
  class: ArgumentError#111
  class: ApplicationError#112
  class: SelectionError#113
  class: NoMessageError#114
  class: UnmatchError#115
  class: ZeroDivisionError#116
  class: EmptyError#117
  class: IndexError#118
  class: AssertionFailure#119
  class: Panic#121
inherits from
  RuntimeError ( Umu::Exception::Abstraction )
has properties
method: initialize / 4 #122
  class: EqualityError#133
  class: OrderError#134
  class: NotImplemented#135
  class: InternalSubclassResponsibility#139
inherits from
  Abstract ( Umu::Exception::Abstraction )

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4  require_relative 'assertion'
   5 
   6 
   7 
   8  module Umu
   9 
  10  module Exception
  11 
  12  module Abstraction
  13 
  14  class Abstract < ::StandardError; end
  15 
  16 
  17 
  18  class Expected < Abstract
  19      attr_reader :msg
  20 
  21 
  22      def initialize(msg, *args)
  23          ASSERT.kind_of msg, ::String
  24 
  25          @msg = format msg, *args
  26      end
  27 
  28 
  29      def to_s
  30          format "[%s] %s", __category__, self.msg
  31      end
  32 
  33 
  34  private
  35 
  36      def __category__
  37          self.class.to_s.split(/::/)[2]
  38      end
  39  end
  40 
  41 
  42 
  43  class ExecutionError < Expected
  44      attr_reader :loc
  45 
  46 
  47      def initialize(loc, msg, *args)
  48          ASSERT.kind_of loc, LOC::Entry
  49 
  50          super(msg, *args)
  51 
  52          @loc = loc
  53      end
  54 
  55 
  56      def to_s
  57          format "%s -- %s", super.to_s, self.loc.to_s
  58      end
  59  end
  60 
  61 
  62 
  63  class RuntimeError < ExecutionError
  64      attr_reader :env
  65 
  66 
  67      def initialize(loc, env, msg, *args)
  68          ASSERT.kind_of loc, LOC::Entry
  69          ASSERT.kind_of env, E::Entry
  70 
  71          super(loc, msg, *args)
  72 
  73          @env = env
  74      end
  75 
  76 
  77      def print_backtrace
  78          self.env.print_backtrace
  79      end
  80  end
  81 
  82 
  83 
  84  class SubclassResponsibility < RuntimeError; end
  85 
  86  end # Umu::Exception::Abstraction
  87 
  88 
  89 
  90  class CommandError < Abstraction::Expected; end
  91 
  92  class SyntaxErrorWithoutLocation < Abstraction::Expected
  93 
  94  private
  95 
  96      def __category__
  97          'SyntaxError'
  98      end
  99  end
 100 
 101 
 102 
 103  class LexicalError          < Abstraction::ExecutionError; end
 104  class SyntaxError           < Abstraction::ExecutionError; end
 105 
 106 
 107 
 108  class NameError             < Abstraction::RuntimeError; end
 109  class TypeError             < Abstraction::RuntimeError; end
 110  class ValueError            < Abstraction::RuntimeError; end
 111  class ArgumentError         < Abstraction::RuntimeError; end
 112  class ApplicationError      < Abstraction::RuntimeError; end
 113  class SelectionError        < Abstraction::RuntimeError; end
 114  class NoMessageError        < Abstraction::RuntimeError; end
 115  class UnmatchError          < Abstraction::RuntimeError; end
 116  class ZeroDivisionError     < Abstraction::RuntimeError; end
 117  class EmptyError            < Abstraction::RuntimeError; end
 118  class IndexError            < Abstraction::RuntimeError; end
 119  class AssertionFailure      < Abstraction::RuntimeError; end
 120 
 121  class Panic < Abstraction::RuntimeError
 122      def initialize(loc, env, msg, *args)
 123          ASSERT.kind_of loc, LOC::Entry
 124          ASSERT.kind_of env, E::Entry
 125          ASSERT.kind_of msg, ::String
 126 
 127          super(loc, env, msg.gsub(/%/, '%%'), *args)
 128      end
 129  end
 130 
 131 
 132 
 133  class EqualityError         < Abstraction::SubclassResponsibility; end
 134  class OrderError            < Abstraction::SubclassResponsibility; end
 135  class NotImplemented        < Abstraction::SubclassResponsibility; end
 136 
 137 
 138 
 139  class InternalSubclassResponsibility < Abstraction::Abstract; end
 140 
 141  end # Umu::Exception
 142 
 143  end # Umu