mooli mooli - 1 year ago 54
Ruby Question

how to get the specific error when fail in ruby

I try to use rescue, but the error that i get is unclear,
and is same error in different cases (e.g in illegal port and already used port.)

require 'socket'

server =
rescue => ex
puts "An error of type #{ex.class} happened, message is #{ex.message}"

and I get
=> An error of type TypeError happened, message is no implicit conversion of nil into String


You may mean to use instead of open(). Open would expect an address to bind, and a block to handle incoming requests, I think.

Regarding the error, it is relatively clear anyway. It is throwing a TypeError which generally means you're giving something the wrong type of input. In this case, you're sending an integer to which (according to this example: seems to be expecting a string and an integer.

I'm wrong! Sorry. Very strange.