|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class MyError < StandardError |
| 4 | + def volt |
| 5 | + raise MyError |
| 6 | + rescue StandardError => e |
| 7 | + puts "#{e.class} : #{e.message}" |
| 8 | + puts e.backtrace.join(' \n') |
| 9 | + ensure |
| 10 | + puts '例外メッセージは以上です!' |
| 11 | + end |
| 12 | + |
| 13 | + def execute_process |
| 14 | + raise MyError, 'プロジェクト固有の例外です!' |
| 15 | + end |
| 16 | + |
| 17 | +rescue MyError => e |
| 18 | + e.backtrace.join(' \n') |
| 19 | +end |
| 20 | + |
| 21 | +# MyError = Class.new(StandardError) |
| 22 | +MyError1 = Class.new(MyError) |
| 23 | +MyError2 = Class.new(MyError) |
| 24 | +MyError3 = Class.new(MyError) |
| 25 | + |
| 26 | +class YouError < RuntimeError |
| 27 | + def anpea |
| 28 | + raise YouError |
| 29 | + rescue StandardError => e |
| 30 | + puts "#{e.class} : #{e.message}" |
| 31 | + puts e.backtrace.join(' \n') |
| 32 | + ensure |
| 33 | + puts '例外メッセージは以上です!' |
| 34 | + end |
| 35 | +end |
| 36 | + |
| 37 | +# YouError = Class.new(ScriptError) |
| 38 | +YouError1 = Class.new(YouError) |
| 39 | +YouError2 = Class.new(YouError) |
| 40 | +YouError3 = Class.new(YouError) |
| 41 | + |
| 42 | +class WhoError < RuntimeError |
| 43 | + def teikou |
| 44 | + raise WhoError |
| 45 | + rescue StandardError => e |
| 46 | + puts "#{e.class} : #{e.message}" |
| 47 | + puts e.backtrace.join(' \n') |
| 48 | + ensure |
| 49 | + puts '例外メッセージは以上です!' |
| 50 | + end |
| 51 | +end |
| 52 | + |
| 53 | +# WhoError = Class.new(SignalException) |
| 54 | +WhoError1 = Class.new(WhoError) |
| 55 | + |
| 56 | +class CatError < RuntimeError |
| 57 | + def kasai |
| 58 | + raise CatError |
| 59 | + rescue StandardError => e |
| 60 | + puts "#{e.class} : #{e.message}" |
| 61 | + puts e.backtrace.join(' \n') |
| 62 | + ensure |
| 63 | + puts '例外メッセージは以上です!' |
| 64 | + end |
| 65 | +end |
| 66 | + |
| 67 | +# CatError = Class.new(NoMemoryError) |
| 68 | +CatError1 = Class.new(CatError) |
| 69 | + |
| 70 | +class DogError < RuntimeError |
| 71 | + def tebunan |
| 72 | + raise DogError |
| 73 | + rescue StandardError => e |
| 74 | + puts "#{e.class} : #{e.message}" |
| 75 | + puts e.backtrace.join(' \n') |
| 76 | + ensure |
| 77 | + puts '例外メッセージは以上です!' |
| 78 | + end |
| 79 | +end |
| 80 | + |
| 81 | +# DogError = Class.new(SystemExit) |
| 82 | +DogError1 = Class.new(DogError) |
| 83 | + |
| 84 | +class Object |
| 85 | + def tanraku |
| 86 | + m = Mutex.new |
| 87 | + |
| 88 | + begin |
| 89 | + m.lock |
| 90 | + raise Object |
| 91 | + rescue StandardError => e |
| 92 | + puts e.backtrace |
| 93 | + print 'Tanraku Method Exception ' |
| 94 | + ensure |
| 95 | + puts '--> next class search...' |
| 96 | + m.unlock |
| 97 | + end |
| 98 | + end |
| 99 | + |
| 100 | + def tanraku_exit |
| 101 | + m2 = Mutex.new |
| 102 | + |
| 103 | + begin |
| 104 | + m2.lock |
| 105 | + raise Object |
| 106 | + rescue StandardError => ef |
| 107 | + puts ef.backtrace |
| 108 | + ensure |
| 109 | + puts '--> Tanraku_Exit Method Exception' |
| 110 | + m2.unlock |
| 111 | + exit! |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + def execute_process |
| 116 | + raise Object |
| 117 | + rescue StandardError => e |
| 118 | + puts "#{e.class} : #{e.message}" |
| 119 | + ensure |
| 120 | + puts ea.backtrace |
| 121 | + end |
| 122 | + |
| 123 | + def tanraku_log |
| 124 | + Dir.mkdir('log', 0o666) unless FileTest.exist?('log') |
| 125 | + File.open('log/logs.txt', 'a:utf-8') do |m2| |
| 126 | + exee = Exception.new('User Exception is raise message.') |
| 127 | + m2.puts exee.message |
| 128 | + raise |
| 129 | + rescue StandardError => e |
| 130 | + File.open('log/logs.txt', 'a:utf-8') do |m| |
| 131 | + m.puts e.backtrace.to_s |
| 132 | + m.puts "#{e.class} : #{e.message}" |
| 133 | + end |
| 134 | + ensure |
| 135 | + puts 'log write (log/logs.txt).' |
| 136 | + end |
| 137 | + end |
| 138 | +end |
| 139 | + |
| 140 | +# module Tanraku |
| 141 | +# VERSION = '1.0.1' |
| 142 | +# end |
| 143 | + |
| 144 | +__END__ |
0 commit comments