Class: ExceptionThrower

Inherits:
Object
  • Object
show all
Defined in:
lib/javonet-ruby-sdk/utils/exceptions/exception_thrower.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/utils/exceptions/exception_thrower.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/utils/exceptions/exception_thrower.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/utils/exceptions/exception_thrower.rb

Class Method Summary collapse

Class Method Details

.get_exception_object(exception_code, exception_message) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/javonet-ruby-sdk/utils/exceptions/exception_thrower.rb', line 43

def self.get_exception_object(exception_code, exception_message)
  case exception_code
  when ExceptionType::EXCEPTION
    return Exception.new("Exception " + exception_message)
  when ExceptionType::IO_EXCEPTION
    return IOError.new("IOError " + exception_message)
  when ExceptionType::FILE_NOT_FOUND_EXCEPTION
    return Errno::ENOENT.new("Errno::ENOENT " + exception_message)
  when ExceptionType::RUNTIME_EXCEPTION
    return RuntimeError.new("RuntimeError " + exception_message)
  when ExceptionType::ARITHMETIC_EXCEPTION
    return ZeroDivisionError.new("ZeroDivisionError " + exception_message)
  when ExceptionType::ILLEGAL_ARGUMENT_EXCEPTION
    return ArgumentError.new("ArgumentError " + exception_message)
  when ExceptionType::INDEX_OUT_OF_BOUNDS_EXCEPTION
    return IndexError.new("IndexError " + exception_message)
  when ExceptionType::NULL_POINTER_EXCEPTION
    return TypeError.new("TypeError " + exception_message)
  else
    return Exception.new(exception_code.to_s + " " + exception_message)
  end
end

.get_local_stack_trace(stack_trace_classes, stack_trace_methods, stack_trace_lines, stack_trace_files) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/javonet-ruby-sdk/utils/exceptions/exception_thrower.rb', line 18

def self.get_local_stack_trace(stack_trace_classes, stack_trace_methods, stack_trace_lines, stack_trace_files)
  stack_classes_array = stack_trace_classes.split("|")
  stack_methods_array = stack_trace_methods.split("|")
  stack_lines_array = stack_trace_lines.split("|")
  stack_files_array = stack_trace_files.split("|")

  stack_trace = ""
  stack_classes_array.each_with_index do |class_name, i|
    if (i < stack_files_array.length and stack_files_array[i] != "")
      stack_trace += "#{stack_files_array[i]}:"
    end
    if (i < stack_lines_array.length and stack_lines_array[i] != "")
      stack_trace += "#{stack_lines_array[i]} "
    end
    if (class_name != "")
      stack_trace += "in '#{class_name}#"
    end
    if (i < stack_methods_array.length and stack_methods_array[i] != "")
      stack_trace += "#{stack_methods_array[i]}'\n"
    end
  end

  return stack_trace
end

.throw_exception(exception_command) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/javonet-ruby-sdk/utils/exceptions/exception_thrower.rb', line 5

def self.throw_exception(exception_command)
  exception_code = exception_command.payload[0]
  javonet_stack_command = exception_command.payload[1]
  exception_name = exception_command.payload[2]
  exception_message = exception_command.payload[3]

  exception_object = get_exception_object(exception_code, exception_message)

  stack_trace = get_local_stack_trace(exception_command.payload[4], exception_command.payload[5], exception_command.payload[6], exception_command.payload[7])
  exception_object.set_backtrace(stack_trace)
  return exception_object
end