Class: ExceptionThrower
- Inherits:
-
Object
- Object
- ExceptionThrower
- Defined in:
- lib/hypertube-ruby-sdk/utils/exceptions/exception_thrower.rb
Overview
frozen_string_literal: true
Class Method Summary collapse
- .get_exception_object(exception_code, exception_message) ⇒ Object
- .get_local_stack_trace(stack_trace_classes, stack_trace_methods, stack_trace_lines, stack_trace_files) ⇒ Object
- .throw_exception(exception_command) ⇒ Object
Class Method Details
.get_exception_object(exception_code, exception_message) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/hypertube-ruby-sdk/utils/exceptions/exception_thrower.rb', line 37 def self.get_exception_object(exception_code, ) case exception_code when ExceptionType::EXCEPTION Exception.new('Exception ' + ) when ExceptionType::IO_EXCEPTION IOError.new('IOError ' + ) when ExceptionType::FILE_NOT_FOUND_EXCEPTION Errno::ENOENT.new('Errno::ENOENT ' + ) when ExceptionType::RUNTIME_EXCEPTION RuntimeError.new('RuntimeError ' + ) when ExceptionType::ARITHMETIC_EXCEPTION ZeroDivisionError.new('ZeroDivisionError ' + ) when ExceptionType::ILLEGAL_ARGUMENT_EXCEPTION ArgumentError.new('ArgumentError ' + ) when ExceptionType::INDEX_OUT_OF_BOUNDS_EXCEPTION IndexError.new('IndexError ' + ) when ExceptionType::NULL_POINTER_EXCEPTION TypeError.new('TypeError ' + ) else Exception.new(exception_code.to_s + ' ' + ) end end |
.get_local_stack_trace(stack_trace_classes, stack_trace_methods, stack_trace_lines, stack_trace_files) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hypertube-ruby-sdk/utils/exceptions/exception_thrower.rb', line 20 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| stack_trace += "#{stack_files_array[i]}:" if i < stack_files_array.length and stack_files_array[i] != '' stack_trace += "#{stack_lines_array[i]} " if i < stack_lines_array.length and stack_lines_array[i] != '' stack_trace += "in '#{class_name}#" if class_name != '' stack_trace += "#{stack_methods_array[i]}'\n" if i < stack_methods_array.length and stack_methods_array[i] != '' end stack_trace end |
.throw_exception(exception_command) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/hypertube-ruby-sdk/utils/exceptions/exception_thrower.rb', line 6 def self.throw_exception(exception_command) exception_code = exception_command.payload[0] stack_command = exception_command.payload[1] exception_name = exception_command.payload[2] = exception_command.payload[3] exception_object = get_exception_object(exception_code, ) 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) exception_object end |