Why can't I send the class error further along with the chain? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceBest practice: Using system supplied or custom exceptions for error conditions in ruby?Ruby Classes; Error: Uninitialized constant BookInStock::ArguementError (NameError)RubyKoans 113/282 - type mismatch:string given / how could i have solved myself with irb?How to prevent auto expansion of hash arguments?wrong number of arguments Contact#createloop a select drop down menu 5 timesRuby copy file by extensionHow do i read lines in txt and use them in a method for ruby, exactly as the text is?Build the hash query from array for mongoid railsRails 5(ajax): wrong number of arguments (given 1, expected 0)
Using "nakedly" instead of "with nothing on"
I'm thinking of a number
Can I throw a sword that doesn't have the Thrown property at someone?
What LEGO pieces have "real-world" functionality?
How did the aliens keep their waters separated?
Can't figure this one out.. What is the missing box?
Why does this iterative way of solving of equation work?
Working around an AWS network ACL rule limit
What is the electric potential inside a point charge?
What's the difference between (size_t)-1 and ~0?
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
Can a 1st-level character have an ability score above 18?
How to market an anarchic city as a tourism spot to people living in civilized areas?
Determine whether f is a function, an injection, a surjection
How is simplicity better than precision and clarity in prose?
Writing Thesis: Copying from published papers
Windows 10: How to Lock (not sleep) laptop on lid close?
What are the performance impacts of 'functional' Rust?
How to add zeros to reach same number of decimal places in tables?
Stop battery usage [Ubuntu 18]
Estimate capacitor parameters
How did passengers keep warm on sail ships?
Limit for e and 1/e
How to rotate it perfectly?
Why can't I send the class error further along with the chain?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceBest practice: Using system supplied or custom exceptions for error conditions in ruby?Ruby Classes; Error: Uninitialized constant BookInStock::ArguementError (NameError)RubyKoans 113/282 - type mismatch:string given / how could i have solved myself with irb?How to prevent auto expansion of hash arguments?wrong number of arguments Contact#createloop a select drop down menu 5 timesRuby copy file by extensionHow do i read lines in txt and use them in a method for ruby, exactly as the text is?Build the hash query from array for mongoid railsRails 5(ajax): wrong number of arguments (given 1, expected 0)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I've got an error in some child class:
(byebug) e.class
CSV::MalformedCSVError
(byebug) e.message.truncate(150, omission: '')
"Illegal quoting in line 1. [SmarterCSV: csv line 1]"
(byebug) e
#<CSV::MalformedCSVError: Illegal quoting in line 1. [SmarterCSV: csv line 1]>
(byebug) raise e.class, e.message.truncate(150, omission: '')
*** ArgumentError Exception: wrong number of arguments (given 1, expected 2)
I want to send the original error class and message to a further class, to rescue all of them without the creation of custom error for each child class (ChildClassError = Class.new(StandardError)).
I will be grateful for the help. I would like to understand the reason.
What's wrong here?
rescue StandardError => e
raise e.class
end
*** ArgumentError Exception: wrong number of arguments (given 0, expected 2)
ruby rescue
add a comment |
I've got an error in some child class:
(byebug) e.class
CSV::MalformedCSVError
(byebug) e.message.truncate(150, omission: '')
"Illegal quoting in line 1. [SmarterCSV: csv line 1]"
(byebug) e
#<CSV::MalformedCSVError: Illegal quoting in line 1. [SmarterCSV: csv line 1]>
(byebug) raise e.class, e.message.truncate(150, omission: '')
*** ArgumentError Exception: wrong number of arguments (given 1, expected 2)
I want to send the original error class and message to a further class, to rescue all of them without the creation of custom error for each child class (ChildClassError = Class.new(StandardError)).
I will be grateful for the help. I would like to understand the reason.
What's wrong here?
rescue StandardError => e
raise e.class
end
*** ArgumentError Exception: wrong number of arguments (given 0, expected 2)
ruby rescue
@AlekseiMatiushkin unfortunately, nope. thanks for the try.
– Alexey Strizhak
Mar 22 at 7:31
I just want to understand, what's happened withraisemethod. The simple solution is:raise ChildClassError, "#e.class: #e.message.truncate(150, omission: '')"
– Alexey Strizhak
Mar 22 at 8:20
add a comment |
I've got an error in some child class:
(byebug) e.class
CSV::MalformedCSVError
(byebug) e.message.truncate(150, omission: '')
"Illegal quoting in line 1. [SmarterCSV: csv line 1]"
(byebug) e
#<CSV::MalformedCSVError: Illegal quoting in line 1. [SmarterCSV: csv line 1]>
(byebug) raise e.class, e.message.truncate(150, omission: '')
*** ArgumentError Exception: wrong number of arguments (given 1, expected 2)
I want to send the original error class and message to a further class, to rescue all of them without the creation of custom error for each child class (ChildClassError = Class.new(StandardError)).
I will be grateful for the help. I would like to understand the reason.
What's wrong here?
rescue StandardError => e
raise e.class
end
*** ArgumentError Exception: wrong number of arguments (given 0, expected 2)
ruby rescue
I've got an error in some child class:
(byebug) e.class
CSV::MalformedCSVError
(byebug) e.message.truncate(150, omission: '')
"Illegal quoting in line 1. [SmarterCSV: csv line 1]"
(byebug) e
#<CSV::MalformedCSVError: Illegal quoting in line 1. [SmarterCSV: csv line 1]>
(byebug) raise e.class, e.message.truncate(150, omission: '')
*** ArgumentError Exception: wrong number of arguments (given 1, expected 2)
I want to send the original error class and message to a further class, to rescue all of them without the creation of custom error for each child class (ChildClassError = Class.new(StandardError)).
I will be grateful for the help. I would like to understand the reason.
What's wrong here?
rescue StandardError => e
raise e.class
end
*** ArgumentError Exception: wrong number of arguments (given 0, expected 2)
ruby rescue
ruby rescue
edited Mar 22 at 8:41
Alexey Strizhak
asked Mar 22 at 7:10
Alexey StrizhakAlexey Strizhak
7918
7918
@AlekseiMatiushkin unfortunately, nope. thanks for the try.
– Alexey Strizhak
Mar 22 at 7:31
I just want to understand, what's happened withraisemethod. The simple solution is:raise ChildClassError, "#e.class: #e.message.truncate(150, omission: '')"
– Alexey Strizhak
Mar 22 at 8:20
add a comment |
@AlekseiMatiushkin unfortunately, nope. thanks for the try.
– Alexey Strizhak
Mar 22 at 7:31
I just want to understand, what's happened withraisemethod. The simple solution is:raise ChildClassError, "#e.class: #e.message.truncate(150, omission: '')"
– Alexey Strizhak
Mar 22 at 8:20
@AlekseiMatiushkin unfortunately, nope. thanks for the try.
– Alexey Strizhak
Mar 22 at 7:31
@AlekseiMatiushkin unfortunately, nope. thanks for the try.
– Alexey Strizhak
Mar 22 at 7:31
I just want to understand, what's happened with
raise method. The simple solution is: raise ChildClassError, "#e.class: #e.message.truncate(150, omission: '')"– Alexey Strizhak
Mar 22 at 8:20
I just want to understand, what's happened with
raise method. The simple solution is: raise ChildClassError, "#e.class: #e.message.truncate(150, omission: '')"– Alexey Strizhak
Mar 22 at 8:20
add a comment |
2 Answers
2
active
oldest
votes
The issue is with CSV::MalformedCSVError#new violating the standard for the exceptions that Kernel#raise expects.
The latter attempts to call Exception#new/1 while the only possible arity of the constructor of CSV::MalformedCSVError is two. You should create an object yourself:
raise CSV::MalformedCSVError.new(e.message.truncate(150, omission: ''), __LINE__)
For the generic case, you probably should get the arity of the constructor and behave correspondingly.
add a comment |
You could do so by just rescuing from StandardError exception like so:
class Foo
attr_reader :value
def initialize(value)
@value = value
end
end
begin
foo = Foo.new
rescue StandardError => e
raise e.class.new(e.message.truncate(150, omission: ''))
end
Though this way, you're reinitializing another object of the same class here with a new/modified message.
Edit: Aleksei made a good point on arity, as a custom error/exception classes are made differently to have fine-grained control over the exceptions that are helpful while debugging. Make sure you have the right arity otherwise you'd be on a goose hunt than solving actual problem.
It didn't work too, actually, thanks for the try
– Alexey Strizhak
Mar 22 at 8:12
@AlexeyStrizhak : What's the message that you see in logs?
– Surya
Mar 22 at 8:16
``` 24: byebug => 25: raise e.class.new(e.message.truncate(150, omission: '')) 26: end 27: pms_csv.imported! 28: end 29: (byebug) raise e.class.new(e.message.truncate(150, omission: '')) *** ArgumentError Exception: wrong number of arguments (given 1, expected 2) nil ```
– Alexey Strizhak
Mar 22 at 8:27
@AlexeyStrizhak : Read the edit section,e.class.new(e.message.truncate(150, omission: ''))where e.class isCSV::MalformedCSVErrorpart which expects two arguments.CSV::MalformedCSVError.:e.class.new(e.message.truncate(150, omission: ''), __LINE__)should be used.
– Surya
Mar 22 at 8:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294567%2fwhy-cant-i-send-the-class-error-further-along-with-the-chain%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The issue is with CSV::MalformedCSVError#new violating the standard for the exceptions that Kernel#raise expects.
The latter attempts to call Exception#new/1 while the only possible arity of the constructor of CSV::MalformedCSVError is two. You should create an object yourself:
raise CSV::MalformedCSVError.new(e.message.truncate(150, omission: ''), __LINE__)
For the generic case, you probably should get the arity of the constructor and behave correspondingly.
add a comment |
The issue is with CSV::MalformedCSVError#new violating the standard for the exceptions that Kernel#raise expects.
The latter attempts to call Exception#new/1 while the only possible arity of the constructor of CSV::MalformedCSVError is two. You should create an object yourself:
raise CSV::MalformedCSVError.new(e.message.truncate(150, omission: ''), __LINE__)
For the generic case, you probably should get the arity of the constructor and behave correspondingly.
add a comment |
The issue is with CSV::MalformedCSVError#new violating the standard for the exceptions that Kernel#raise expects.
The latter attempts to call Exception#new/1 while the only possible arity of the constructor of CSV::MalformedCSVError is two. You should create an object yourself:
raise CSV::MalformedCSVError.new(e.message.truncate(150, omission: ''), __LINE__)
For the generic case, you probably should get the arity of the constructor and behave correspondingly.
The issue is with CSV::MalformedCSVError#new violating the standard for the exceptions that Kernel#raise expects.
The latter attempts to call Exception#new/1 while the only possible arity of the constructor of CSV::MalformedCSVError is two. You should create an object yourself:
raise CSV::MalformedCSVError.new(e.message.truncate(150, omission: ''), __LINE__)
For the generic case, you probably should get the arity of the constructor and behave correspondingly.
answered Mar 22 at 7:37
Aleksei MatiushkinAleksei Matiushkin
84.8k95896
84.8k95896
add a comment |
add a comment |
You could do so by just rescuing from StandardError exception like so:
class Foo
attr_reader :value
def initialize(value)
@value = value
end
end
begin
foo = Foo.new
rescue StandardError => e
raise e.class.new(e.message.truncate(150, omission: ''))
end
Though this way, you're reinitializing another object of the same class here with a new/modified message.
Edit: Aleksei made a good point on arity, as a custom error/exception classes are made differently to have fine-grained control over the exceptions that are helpful while debugging. Make sure you have the right arity otherwise you'd be on a goose hunt than solving actual problem.
It didn't work too, actually, thanks for the try
– Alexey Strizhak
Mar 22 at 8:12
@AlexeyStrizhak : What's the message that you see in logs?
– Surya
Mar 22 at 8:16
``` 24: byebug => 25: raise e.class.new(e.message.truncate(150, omission: '')) 26: end 27: pms_csv.imported! 28: end 29: (byebug) raise e.class.new(e.message.truncate(150, omission: '')) *** ArgumentError Exception: wrong number of arguments (given 1, expected 2) nil ```
– Alexey Strizhak
Mar 22 at 8:27
@AlexeyStrizhak : Read the edit section,e.class.new(e.message.truncate(150, omission: ''))where e.class isCSV::MalformedCSVErrorpart which expects two arguments.CSV::MalformedCSVError.:e.class.new(e.message.truncate(150, omission: ''), __LINE__)should be used.
– Surya
Mar 22 at 8:47
add a comment |
You could do so by just rescuing from StandardError exception like so:
class Foo
attr_reader :value
def initialize(value)
@value = value
end
end
begin
foo = Foo.new
rescue StandardError => e
raise e.class.new(e.message.truncate(150, omission: ''))
end
Though this way, you're reinitializing another object of the same class here with a new/modified message.
Edit: Aleksei made a good point on arity, as a custom error/exception classes are made differently to have fine-grained control over the exceptions that are helpful while debugging. Make sure you have the right arity otherwise you'd be on a goose hunt than solving actual problem.
It didn't work too, actually, thanks for the try
– Alexey Strizhak
Mar 22 at 8:12
@AlexeyStrizhak : What's the message that you see in logs?
– Surya
Mar 22 at 8:16
``` 24: byebug => 25: raise e.class.new(e.message.truncate(150, omission: '')) 26: end 27: pms_csv.imported! 28: end 29: (byebug) raise e.class.new(e.message.truncate(150, omission: '')) *** ArgumentError Exception: wrong number of arguments (given 1, expected 2) nil ```
– Alexey Strizhak
Mar 22 at 8:27
@AlexeyStrizhak : Read the edit section,e.class.new(e.message.truncate(150, omission: ''))where e.class isCSV::MalformedCSVErrorpart which expects two arguments.CSV::MalformedCSVError.:e.class.new(e.message.truncate(150, omission: ''), __LINE__)should be used.
– Surya
Mar 22 at 8:47
add a comment |
You could do so by just rescuing from StandardError exception like so:
class Foo
attr_reader :value
def initialize(value)
@value = value
end
end
begin
foo = Foo.new
rescue StandardError => e
raise e.class.new(e.message.truncate(150, omission: ''))
end
Though this way, you're reinitializing another object of the same class here with a new/modified message.
Edit: Aleksei made a good point on arity, as a custom error/exception classes are made differently to have fine-grained control over the exceptions that are helpful while debugging. Make sure you have the right arity otherwise you'd be on a goose hunt than solving actual problem.
You could do so by just rescuing from StandardError exception like so:
class Foo
attr_reader :value
def initialize(value)
@value = value
end
end
begin
foo = Foo.new
rescue StandardError => e
raise e.class.new(e.message.truncate(150, omission: ''))
end
Though this way, you're reinitializing another object of the same class here with a new/modified message.
Edit: Aleksei made a good point on arity, as a custom error/exception classes are made differently to have fine-grained control over the exceptions that are helpful while debugging. Make sure you have the right arity otherwise you'd be on a goose hunt than solving actual problem.
answered Mar 22 at 7:45
SuryaSurya
13.1k23558
13.1k23558
It didn't work too, actually, thanks for the try
– Alexey Strizhak
Mar 22 at 8:12
@AlexeyStrizhak : What's the message that you see in logs?
– Surya
Mar 22 at 8:16
``` 24: byebug => 25: raise e.class.new(e.message.truncate(150, omission: '')) 26: end 27: pms_csv.imported! 28: end 29: (byebug) raise e.class.new(e.message.truncate(150, omission: '')) *** ArgumentError Exception: wrong number of arguments (given 1, expected 2) nil ```
– Alexey Strizhak
Mar 22 at 8:27
@AlexeyStrizhak : Read the edit section,e.class.new(e.message.truncate(150, omission: ''))where e.class isCSV::MalformedCSVErrorpart which expects two arguments.CSV::MalformedCSVError.:e.class.new(e.message.truncate(150, omission: ''), __LINE__)should be used.
– Surya
Mar 22 at 8:47
add a comment |
It didn't work too, actually, thanks for the try
– Alexey Strizhak
Mar 22 at 8:12
@AlexeyStrizhak : What's the message that you see in logs?
– Surya
Mar 22 at 8:16
``` 24: byebug => 25: raise e.class.new(e.message.truncate(150, omission: '')) 26: end 27: pms_csv.imported! 28: end 29: (byebug) raise e.class.new(e.message.truncate(150, omission: '')) *** ArgumentError Exception: wrong number of arguments (given 1, expected 2) nil ```
– Alexey Strizhak
Mar 22 at 8:27
@AlexeyStrizhak : Read the edit section,e.class.new(e.message.truncate(150, omission: ''))where e.class isCSV::MalformedCSVErrorpart which expects two arguments.CSV::MalformedCSVError.:e.class.new(e.message.truncate(150, omission: ''), __LINE__)should be used.
– Surya
Mar 22 at 8:47
It didn't work too, actually, thanks for the try
– Alexey Strizhak
Mar 22 at 8:12
It didn't work too, actually, thanks for the try
– Alexey Strizhak
Mar 22 at 8:12
@AlexeyStrizhak : What's the message that you see in logs?
– Surya
Mar 22 at 8:16
@AlexeyStrizhak : What's the message that you see in logs?
– Surya
Mar 22 at 8:16
``` 24: byebug => 25: raise e.class.new(e.message.truncate(150, omission: '')) 26: end 27: pms_csv.imported! 28: end 29: (byebug) raise e.class.new(e.message.truncate(150, omission: '')) *** ArgumentError Exception: wrong number of arguments (given 1, expected 2) nil ```
– Alexey Strizhak
Mar 22 at 8:27
``` 24: byebug => 25: raise e.class.new(e.message.truncate(150, omission: '')) 26: end 27: pms_csv.imported! 28: end 29: (byebug) raise e.class.new(e.message.truncate(150, omission: '')) *** ArgumentError Exception: wrong number of arguments (given 1, expected 2) nil ```
– Alexey Strizhak
Mar 22 at 8:27
@AlexeyStrizhak : Read the edit section,
e.class.new(e.message.truncate(150, omission: '')) where e.class is CSV::MalformedCSVError part which expects two arguments. CSV::MalformedCSVError.: e.class.new(e.message.truncate(150, omission: ''), __LINE__) should be used.– Surya
Mar 22 at 8:47
@AlexeyStrizhak : Read the edit section,
e.class.new(e.message.truncate(150, omission: '')) where e.class is CSV::MalformedCSVError part which expects two arguments. CSV::MalformedCSVError.: e.class.new(e.message.truncate(150, omission: ''), __LINE__) should be used.– Surya
Mar 22 at 8:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294567%2fwhy-cant-i-send-the-class-error-further-along-with-the-chain%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@AlekseiMatiushkin unfortunately, nope. thanks for the try.
– Alexey Strizhak
Mar 22 at 7:31
I just want to understand, what's happened with
raisemethod. The simple solution is:raise ChildClassError, "#e.class: #e.message.truncate(150, omission: '')"– Alexey Strizhak
Mar 22 at 8:20