マイペースなプログラミング日記

DTMやプログラミングにお熱なd-kamiがマイペースに書くブログ

例外作成 #6

まず、以下のファイルを作成した

./vm/exception/Exception.rb

そして中身は

class NotImplementedException < Exception; end

これはvmクラスのexecuteメソッドで使っている。取得した命令が未実装の場合、この例外を発生させる。メッセージには命令コードを16進数にしたものを持たせている

def execute()
    code = getCode()
    instruction = @instructions.getInstruction(code)
        
    if instruction == nil then
        raise NotImplementedException, "Not Implmeneted " << code.to_s(16)
    end
        
    instruction.execute(self)
        
    #命令コードと実行したクラスを表示
    puts code.to_s(16) + ": " + instruction.class().to_s()
        
    #EAXの値を表示する
    puts "EAX = " + @registers[EAX].to_s(16)
        
    #EIPの値を表示する
    puts "EIP = " + @registers[EIP].to_s(16)
end