Ruby에서 AOP를 사용하여 예외를 처리하려고합니다. 여기에 사용 된 툴킷은 Aquarium (http://aquarium.rubyforge.org/)입니다.Ruby의 SystemStackError Aquarium (Aspect Oriented Programming)을 사용한 예외 처리
필자는 작성된 ApplicationController 클래스의 모든 하위 항목 (하위 클래스)을 샘플 코드로 작성했습니다.
다음 프로그램을 실행하면 SystemStackError가 발생합니다 ("ulimit -s"를 사용하여 스택 제한을 설정해 보았습니다). 누군가 나를 도와주세요!. 또는 맵핑에 대한 제안 사항 : 수퍼 클래스의 서브 클래스 all_methods를 환영합니다. 미리 감사드립니다.
require 'aquarium'
include Aquarium::Aspects
class ApplicationController
end
class Abc < ApplicationController
def func
puts "func called"
raise Exception.new # SystemStackError is thrown before reaching place
end
end
#Dummy class
class Def < ApplicationController
end
Aspect.new :after_raising => Exception,
:in_types_and_descendents => "ApplicationController" do |jp, object, *args|
puts "Exception Handling Code"
end
a = Abc.new
a.func
당신은 모듈 (또는 스칼라의 특성을)이없는 경우에만 자바와 같은 언어에 대한 감각을 만드는 방법을 사용하도록 의무화했습니다
here를 찾을 수 있습니다. –
아니요, 작동하지 않습니다. –
어쩌면 당신은 http://apidock.com/rails/ActiveSupport/Rescuable/ClassMethods/rescue_from 같은 것을 사용할 수 있습니까? – Fivell