Skip to content

Instantly share code, notes, and snippets.

View taisyo7333's full-sized avatar

Daisuke Inoue taisyo7333

View GitHub Profile
@taisyo7333
taisyo7333 / ParseInt.cs
Created November 7, 2015 01:24
[C#] 整数で構成される文字列をint型に変換する.(Parseを使用せずにLINQを使用してみる)
using System;
using System.Linq;
namespace ParseInt
{
class Program
{
static void Main(string[] args)
{
// Success
@taisyo7333
taisyo7333 / output.log
Created November 8, 2015 12:35
半角空白で区切られた単語を単語ごとに分割して配列に格納する方法。(再帰版)
This
is
a
pen
@taisyo7333
taisyo7333 / Code3-160.rb
Last active January 24, 2016 09:16
Ruby Exception rescue
# encoding: SJIS
def foo
-1 / 0
rescue
p 1
end
foo
# => 1
@taisyo7333
taisyo7333 / Code3-158.rb
Created January 24, 2016 09:18
Ruby Exception
# encoding: SJIS
begin # run
p 1
rescue # Do not run , because of no-execption occurs.
p 0
else # run , because of no-execption occurs.
p 2
ensure # run always at last.
p 3
@taisyo7333
taisyo7333 / Code3-159.rb
Created January 24, 2016 09:20
Ruby Exception sample
# encoding: SJIS
1/0 rescue p 1
@taisyo7333
taisyo7333 / Code3-161.rb
Last active January 24, 2016 09:31
Ruby Exception object
# encoding: SJIS
begin
1/0
rescue ZeroDivisionError => e
p e.backtrace
end
@taisyo7333
taisyo7333 / Code3-162.rb
Created January 24, 2016 09:33
Ruby Exception $!
# encoding: SJIS
begin
1/0
rescue ZeroDivisionError
p $!.class # => ZeroDivisionError
raise # => ZeroDivisionError
end
@taisyo7333
taisyo7333 / Code3-163.rb
Created January 24, 2016 10:19
Ruby Exception [retry]
# encoding: SJIS
a = 0
begin
b = 1 / a
rescue ZeroDivisionError
a += 1
retry
ensure
p b
@taisyo7333
taisyo7333 / Code3-164.rb
Created January 24, 2016 10:20
Ruby Exception
# encoding: SJIS
begin
1/0
rescue
p 1
rescue ZeroDivisionError # Do not call
p 2
end
# => 1
@taisyo7333
taisyo7333 / Code3-165.rb
Created January 24, 2016 10:26
Ruby throw - catch
# encoding: SJIS
def foo
throw :exit
end
catch(:exit) {
foo
p 1 # Do not call
}