Bob Bobrov
2008-Jul-12 17:05 UTC
Raising exceptions and "wrong number of arguments" problem
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. -- Posted via http://www.ruby-forum.com/.
Alex Fenton
2008-Jul-12 17:16 UTC
[wxruby-users] Raising exceptions and "wrong number of arguments" problem
Bob Bobrov wrote:> 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.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
Bob Bobrov
2008-Jul-12 19:42 UTC
[wxruby-users] Raising exceptions and "wrong number of arguments" probl
Alex Fenton 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) > > alexThank you very much, Alex :-) -- Posted via http://www.ruby-forum.com/.