mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@15 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
94 lines
2 KiB
Ruby
94 lines
2 KiB
Ruby
#
|
|
# e2mmap.rb - for ruby 1.1
|
|
# $Release Version: 1.1$
|
|
# $Revision: 1.1.1.1 $
|
|
# $Date: 1998/01/16 04:05:49 $
|
|
# by Keiju ISHITSUKA
|
|
#
|
|
# --
|
|
#
|
|
#
|
|
if VERSION < "1.1"
|
|
require "e2mmap1_0.rb"
|
|
else
|
|
|
|
module Exception2MessageMapper
|
|
RCS_ID='-$Header: /home/cvsroot/ruby/lib/e2mmap.rb,v 1.1.1.1 1998/01/16 04:05:49 matz Exp $-'
|
|
|
|
E2MM = Exception2MessageMapper
|
|
|
|
def E2MM.extend_object(cl)
|
|
super
|
|
cl.bind(self)
|
|
end
|
|
|
|
# 以前との互換性のために残してある.
|
|
def E2MM.extend_to(b)
|
|
c = eval("self", b)
|
|
c.extend(self)
|
|
end
|
|
|
|
# public :fail
|
|
# alias e2mm_fail fail
|
|
|
|
def fail(err = nil, *rest)
|
|
Exception2MessageMapper.fail Exception2MessageMapper::ErrNotRegisteredException, err.to_s
|
|
end
|
|
|
|
def bind(cl)
|
|
self.module_eval %q^
|
|
E2MM_ErrorMSG = {}
|
|
# fail(err, *rest)
|
|
# err: 例外
|
|
# rest: メッセージに渡すパラメータ
|
|
#
|
|
def self.fail(err = nil, *rest)
|
|
$@ = caller(0) if $@.nil?
|
|
$@.shift
|
|
if form = E2MM_ErrorMSG[err]
|
|
$! = err.new(sprintf(form, *rest))
|
|
# e2mm_fail()
|
|
raise()
|
|
# elsif self == Exception2MessageMapper
|
|
# fail Exception2MessageMapper::ErrNotRegisteredException, err.to_s
|
|
else
|
|
# print "super\n"
|
|
super
|
|
end
|
|
end
|
|
class << self
|
|
public :fail
|
|
end
|
|
|
|
# def_exception(c, m)
|
|
# c: exception
|
|
# m: message_form
|
|
# 例外cのメッセージをmとする.
|
|
#
|
|
def self.def_e2message(c, m)
|
|
E2MM_ErrorMSG[c] = m
|
|
end
|
|
|
|
# def_exception(c, m)
|
|
# n: exception_name
|
|
# m: message_form
|
|
# s: 例外スーパークラス(デフォルト: Exception)
|
|
# 例外名``c''をもつ例外を定義し, そのメッセージをmとする.
|
|
#
|
|
#def def_exception(n, m)
|
|
def self.def_exception(n, m, s = Exception)
|
|
n = n.id2name if n.kind_of?(Fixnum)
|
|
e = Class.new(s)
|
|
const_set(n, e)
|
|
E2MM_ErrorMSG[e] = m
|
|
# const_get(:E2MM_ErrorMSG)[e] = m
|
|
end
|
|
^
|
|
end
|
|
|
|
extend E2MM
|
|
def_exception(:ErrNotClassOrModule, "Not Class or Module")
|
|
def_exception(:ErrNotRegisteredException, "not registerd exception(%s)")
|
|
end
|
|
end
|
|
|