Tagged Questions
1
vote
2answers
29 views
Catching timeout exception in for-loop
For each file in directory, I need to do something to it, and then write the results to another file. If a timeout exception is raised, continue on to the next iteration of the loop.
require ...
0
votes
1answer
30 views
Ruby statement with embedded SQL INSERT - Syntax error
I have the following Ruby script: It creates a database, reads a csv file and inserts each row into the database.
require "sqlite3"
require "csv"
require "pp"
begin
db = ...
0
votes
0answers
19 views
How to define a class/group/set of exceptions
How should I categorize exceptions?
When creating an object on a web service, errors like unauthorized request, missing argument, wrong argument can happen. Each of these errors has an error code. ...
1
vote
2answers
36 views
Handle default exception in ruby
How do I implement default behavior for an Exception? begin rescue else doesn't work(which I think should).
And, isn't else meaningless in the scenario? Any code that has to run when no exception is ...
0
votes
1answer
27 views
rake still aborts on RuntimeError even though exception is rescued
I am working on a rake system, and I have some new code which needs to do some consistency checking. I would like the code to not exit on the first error; I would like it to continue to finish checks ...
-1
votes
1answer
27 views
Ruby: rescue an OAuthException exception
I'm occasionally getting an OAuthException and am trying to catch it with:
rescue OAuthException => exception
# exception handling code here
However I get:
rescue in <main>': ...
0
votes
2answers
37 views
Rescuing bash/system STDERR in Ruby
I'm shelling out of my Ruby script to call a system command as follows
puts "Reached point #1"
begin
system("sh my_shell_script.sh")
rescue StandardError => e
puts "There was an error"
end
...
0
votes
1answer
30 views
error management service for my Ruby on Rails project
I am looking for error management service for my Ruby on Rails project, Can any one suggest the best tool with lower price.
I have 5 Rails projects.
I found one tool http://www.batbugger.io/ is free ...
0
votes
1answer
33 views
superclass mismatch: get class object (ruby)
class A
end
class B
end
class Y < A
end
class Y < B # TypeError: superclass mismatch for Y
end
Is there a way to get the class the raises the superclass mismatch?
I would like to know that it ...
1
vote
1answer
208 views
File.delete throws Errno:EACCESS Permission Denied in ruby
The following code that is meant to delete lines that match a regular expression fails
def delete_entry(name)
puts "Deleting #{name}.." if $DEBUG
begin
File.open("#{@file_name}.tmp", ...
9
votes
1answer
61 views
Difference between $! versus a variable with rescue
When rescuing from an exception, there are two ways to refer to the raised exception:
begin
...
rescue Exception => e
handle_the_error(e)
end
and
begin
...
rescue Exception
...
0
votes
2answers
71 views
Ruby: Rescuing the same error type twice
Is it possible to rescue the same error type more than once in ruby? I am needing to while using the Koala facebook API library like so:
begin
# Try with user provided app token
fb = ...
1
vote
0answers
63 views
How to send manually exceptions to NewRelic (Ruby)?
How I can send rescued exceptions to NewRelic ?
I have a test file rpm.rb:
require 'newrelic_rpm'
NewRelic::Agent.manual_start
begin
"2" + 3
rescue TypeError => e
puts "whoa !"
...
0
votes
1answer
30 views
Need ruby error message as instance variable
I have a custom error class like this:
class EntityCrudError < StandardError
attr_reader :action
attr_reader :modelName
attr_reader :entity
attr_reader :errors
def ...
4
votes
1answer
64 views
Ruby exception.message taking too much time
I am seeing very interesting and catastrophic behavior with ruby, see the code below
class ExceptionTest
def test
@result = [0]*500000
begin
no_such_method
rescue Exception ...
1
vote
1answer
70 views
Change Ruby exception class to prepend text to original exception message
There is an original exception class that is a subclass of StandardError and its exceptions are thrown as raise RequiredArgumentMissingError 'message'. In my application, I need to change this class ...
0
votes
1answer
68 views
Exception is only caught with `rescue` at the end of the line but not when using a `begin rescue` block
I have a statement that fails:
result = service.load_data()
Now the following suppresses the error and I can then check for nil
result = service.load_data() rescue nil
But when I do the ...
2
votes
2answers
182 views
Ruby custom error classes: the message attribute, and inheritance
I can't seem to find much information about custom exception classes.
What I do know
You can declare your custom error class and let it inherit from StandardError, so it can be rescued:
class ...
0
votes
1answer
49 views
OptionParser throwing 'Missing Argument' for no reasons
I only have 1 possible option and it is parsed as following:
def parse_options
options = {}
options[:markdown] = false
OptionParser.new do |opts|
opts.on('-md', '--markdown', ...
2
votes
2answers
108 views
Why does capturing named groups in Ruby result in “undefined local variable or method” errors?
I am having trouble with named captures in regular expressions in Ruby 2.0. I have a string variable and an interpolated regular expression:
str = "hello world"
re = /\w+/
/(?<greeting>#{re})/ ...
6
votes
2answers
146 views
Exceptions: why does adding parenthesis change anything?
There are a few things I'd like to understand in how Ruby treats inline Error handlers
Case 1
This is a common use case
def foo
raise Error
end
bar = foo rescue 1
# => 1
bar
# => 1
It ...
1
vote
2answers
46 views
Convention for naming Ruby exceptions
I already have quite a number of libraries published. What I haven't decided yet is how to name my exceptions. The Ruby standard library always names the exceptions as such (a noun that is Exception ...
3
votes
1answer
232 views
How to Rescue from ActionDispatch::ParamsParser::ParseError in Rails 4
Rails 4 adds an exception ActionDispatch::ParamsParser::ParseError exception but since its in the middleware stack it appears it can't be rescued in the normal controller environment. In a json API ...
1
vote
1answer
63 views
How to ensure to close database connection in Ruby?
I am learning Ruby. I am trying to make a connection to MySQL db using mysql gem. One of my concern is connection closing.
How should I ensure the connection closing at unexpected situations such as ...
2
votes
1answer
64 views
In Ruby, why aren't variable names in the stack trace?
In a rails app with associations (Such as Post belongs_to user), a common exception is this:
NoMethodError: undefined method `user' for nil:NilClass
Ubiquitously, this causes beginners to believe ...
-7
votes
2answers
178 views
How to get the reference alive to the older one, when there is a second exception in Ruby?
begin
raise "explosion"
rescue
p $!
raise "Are you mad"
p $!
end
# #<RuntimeError: explosion>
# RuntimeError: Are you mad
# from (irb):5:in `rescue in irb_binding'
# from (irb):1
...
1
vote
1answer
64 views
Rescue given anonymous module instead of exception class
We can put a class or module after a rescue statement, but in the code below, I see a method following rescue, which does not fit into this pattern. How is it working and how is it producing the ...
1
vote
2answers
93 views
Why can't `rescue` catch exception classes other than `StandardError` by default?
Why has Ruby been designed to handle only StandardError exceptions implicitly by rescue? For other exceptions, why should we need to put them explicitly with rescue?
begin
#codes here which may ...
2
votes
2answers
263 views
Can't rescue YAML.load exception
I'm trying to handle loading invalid YAML data in Ruby, but seem to be unable to rescue exceptions raised by psych.
This is some example code to demonstrate the issue I'm having:
require 'yaml'
...
0
votes
1answer
119 views
Ruby on Rails Routing Error uninitialized constant
am new whit ruby, have this exception
Routing Error
uninitialized constant
i do everything that in this forum said , but dosent work
this is my db
class CreateCredits < ActiveRecord::Migration
...
1
vote
1answer
255 views
Net/SSH.start doesn't raise an exception if it fails
I'm using Net::SSH to connect to another server. It works fine, but I want to be able to deal with situations where it can't connect. Documentation for the method mentions nothing about exceptions, ...
2
votes
3answers
397 views
An ActiveRecord::RecordNotUnique occurred in registrations#create WHY?
I get an exception and I want to understand why. I've created a git repo so anyone can test it.
The rails app is fresh with Devise installed on it.
Running the app and this script that try to create ...
0
votes
1answer
110 views
Rescue NameError just in this class
I've got a Ruby script and I'm doing this
module MyModule
class MyClass
def do_something
begin
deployer_object = ...
0
votes
2answers
254 views
unable to catch ruby exception
Having the following, long running rake batch:
class SyncStarredRepo
include Mongoid::Document
def self.update
User.all.map do |user|
if user.email != "[email protected]"
...
0
votes
1answer
182 views
MissingTemplate exception raised in mailer using delayed job
I use delayed job to carry out background tasks in my app. It does some stuff and then sends a mail. This is an example of the code block preformed as a delayed job.
def task
# do stuff
...
1
vote
1answer
65 views
Does Ruby's “raise” modify exception?
Does Ruby's "raise" modify exception?
Or, are following snippets:
some_method(MyException.new)
and
begin
raise MyException.new
rescue MyException => e
some_method(e)
end
equivalent? If ...
6
votes
4answers
171 views
What is wrong with this rescue example?
x = StandardError.new(:hello)
y = StandardError.new(:hello)
x == y # => true
x === y # => true
begin
raise x
rescue x
puts "ok" # gets printed
end
begin
raise x
rescue y
puts "ok" # ...
2
votes
2answers
228 views
How to fix a Ruby “no such file to load — xsd/qname” error?
I'm trying to run the FlightXML2 Ruby library for accessing the FlightAware API. (The library's code is here: https://github.com/flightaware/flightxml2-client-ruby)
When including the library file ...
0
votes
0answers
110 views
how to catch exceptions in eventmachine
I'm using eventmachine 1.0.0 with ruby 1.9.3. Now when an exception occurs it's silently ignored. The reactor continues to run, nothing is output. Of course I don't have any custom rescue commands ...
0
votes
4answers
57 views
How to refactor this Ruby code to check for valid paramaters?
Is there a better (more eloquent) way to check for valid params?
def load_data filename, start_percent, end_percent
raise 'Values must be [0,1]' if start_percent < 0
raise 'Values must be ...
0
votes
1answer
106 views
Rufus Scheduler - Catch exception and perform conditional statement
I have the a rufus scheduler which executes a request to Dropbox to check if the access key and secret are authorised every 10 minutes.
If it is unauthorised, the following exception is reported:
...
3
votes
6answers
85 views
How can I make this ruby code throw an exception and bail?
I want this to throw an exception and die:
begin
if meridian != "AM" and meridian != "PM"
rescue
puts MESSAGE
end
end
I googled a lot, but nothing seems to work. I want an if ...
2
votes
2answers
227 views
Rescue Exception with messages
I get exception Thrift::TransportException (end of file reached) and I want to rescue it with the message("end of file reached").
Now I do
begin
#...
rescue Thrift::TransportException => e
...
0
votes
2answers
555 views
How to rescue the error exception raised by the `constantize` method?
I am using Ruby on Rails 3.2.2 and I would like to properly rescue the following process flow by raising a "custom" error message:
def rescue_method
# sample_string.class
# => String
# ...
0
votes
0answers
290 views
ruby and selenium-webdriver on raspberry pi -> Address family not supported by protocol - socket(2) (Errno::EAFNOSUPPORT)
I want to run a ruby scrip on my Raspberry Pi. I've installed ruby via rvm. I'm sure, I'm using the right version:
$ rvm current
ruby-1.9.3-p194
when i run my script, then i get following:
...
8
votes
2answers
541 views
Why does a range with invalid arguments sometimes not cause an argument error?
The following code causes an argument error:
n = 15
(n % 4 == 0)..(n % 3 == 0)
# => bad value for range (ArgumentError)
which I think is because it evaluates to:
false..true
and different ...
0
votes
1answer
74 views
Common way of error-handling when using an external ruby-library
i am creating a ruby-library (but in fact i am a java developer), that can be used by anyone If something goes wrong in a library what scenario would you prefer, that i raise an exception or that i ...
-1
votes
2answers
176 views
rescuing multiple exception of the same type in Rails
Imagine this scenario (just a sample)
file = open("/file1")
file2 = open("/file2")
file3 = open("/file3")
How can i handle this situation, what i want to do is allow statements that don't rise ...
1
vote
2answers
122 views
Break out of ruby inner block using catch/throw
I am interested in breaking out of both the outer and inner block if an exception is thrown in an inner ruby block. The code might look something like this:
catch "ExitBlock" do
...
1
vote
1answer
30 views
Good way to catch exception in one method among several classes
Currently I have several classes, each of which deals with different sites. They act like the same type, in the sense that they all have crawl_item() method.
class CrawlA
def crawl_item
...
...