# Raising exceptions and "wrong number of arguments" problem

**URL:** <https://www.ruby-forum.com/t/raising-exceptions-and-wrong-number-of-arguments-problem/142884>\
**Category:** wxRuby\
**Created:** [July 12, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/raising-exceptions-and-wrong-number-of-arguments-problem/142884 "2008-07-12T19:05:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![syg6](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@syg6](https://www.ruby-forum.com/u/syg6)\
**Post date:** [July 12, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/raising-exceptions-and-wrong-number-of-arguments-problem/142884/1 "2008-07-12T19:05:09Z")

</div>

Hi everyone - what is the proper way to display error messages when you  
raise exceptions?

For example, the following code…

class MyWxRubyClass  
some code…  
evt\_button(my\_button) do  
begin  
some code…  
if wrong\_condition  
raise “My Error Message”  
end  
some code…  
rescue Exception =\> msg  
puts msg  
Wx::MessageDialog.new(nil, msg, ‘Error Popup’,  
Wx::OK|Wx::ICON\_ERROR).show\_modal  
end  
end  
end

… produces “wrong # of arguments(1 for 0)” error message in both  
console and message box.  
How can I make it to display “My Error Message”?  
“Wrong # of arguments(1 for 0)” happens only when I raise my own error  
messages, ruby’s native error messages are being displayd well.

---

<div class="post-metadata">

**Author:** ![syg6](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@syg6](https://www.ruby-forum.com/u/syg6)\
**Post date:** [July 12, 2008, 7:19pm UTC](https://www.ruby-forum.com/t/raising-exceptions-and-wrong-number-of-arguments-problem/142884/2 "2008-07-12T19:19:07Z")

</div>

Bob Bobrov wrote:

> ```
> if wrong_condition
> 
> ```
> 
> … produces “wrong # of arguments(1 for 0)” error message in both  
> console and message box.  
> Use Kernel.raise, eg  
> Kernel.raise “My Error Message”

The reason this is needed is because if you’re inside a class that  
inherits from Wx::Window, a call to ‘raise’ unqualified is taken to mean  
the instance method Window#raise (which takes no arguments)

alex

---

<div class="post-metadata">

**Author:** ![syg6](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@syg6](https://www.ruby-forum.com/u/syg6)\
**Post date:** [July 12, 2008, 9:42pm UTC](https://www.ruby-forum.com/t/raising-exceptions-and-wrong-number-of-arguments-problem/142884/3 "2008-07-12T21:42:06Z")

</div>

Alex F. wrote:

> The reason this is needed is because if you’re inside a class that  
> inherits from Wx::Window, a call to ‘raise’ unqualified is taken to mean  
> the instance method Window#raise (which takes no arguments)
> 
> alex

Thank you very much, Alex 🙂
