Ask a Question related to Ruby, Design and Development.
-
John W. Long #1
Raising Excepitons
Hi,
I'm curious. In code I often raise my own exceptions with:
raise "custom error message"
When is it a good idea to subclass and create my own error class? So far
I've never needed to pass along custom information (other than the message).
It seems like it might make testing better:
assert_raises(MyError) { ... }
instead of:
assert_raises(RuntimeError) { ... }
Are there any other advantages? Are there times when it's convention to
create your own?
___________________
John Long
[url]www.wiseheartdesign.com[/url]
John W. Long Guest
-
Raising a click event
I created a custom control - inheriting from WebControl. How do I give this control a click event for the user of the control to put some code... -
Event raising question
Hi, I have a question regarding events in a composite web control. In windows forms when I programmatically set the SelectedIndex property of a... -
raising car sound / pitching?
Is it possible to pitch a sound in director? Or how can I create a dynamic sound for a driving game? thanks for any help -
raising event
Assuming you have an event handler written for the "ontextchanged" event of the textbox, why don't you just call it directly? -- HTH, Kevin... -
Raising an Event via Code
Our web application has a user control on a web page to display hierarchical data and allow the user to "drill- down" the hierarchy tree. The user... -
David Naseby #2
Re: Raising Excepitons
>-----Original Message-----
>From: John W. Long [mailto:ws@johnwlong.com]Your testing example was good, and similarly, it also aids in debugging down>When is it a good idea to subclass and create my own error
>class?
the line. For example, if you have a method that opens a file and
manipulates the data, its generally a good idea to know if an exception
coming out of that method is related to the file ops or due to some use of
the standard library, or from a defined bad operation from your code (error
condition). Defining a derived exception class is a bit safer for client
code to handle, rather than just parsing the exception message.
David
David Naseby Guest
-
Robert Klemme #3
Re: Raising Excepitons
"David Naseby" <david.naseby@eonesolutions.com.au> schrieb im Newsbeitrag
news:C1B5ED61365AD511805500D0B7B697C633DAEF@sydeon e.eonesolutions.com.au...down>> >-----Original Message-----
> >From: John W. Long [mailto:ws@johnwlong.com]>> >When is it a good idea to subclass and create my own error
> >class?
> Your testing example was good, and similarly, it also aids in debuggingof> the line. For example, if you have a method that opens a file and
> manipulates the data, its generally a good idea to know if an exception
> coming out of that method is related to the file ops or due to some use(error> the standard library, or from a defined bad operation from your codeNot only is it "a bit safer" but it's much cleaner (and maybe faster,> condition). Defining a derived exception class is a bit safer for client
> code to handle, rather than just parsing the exception message.
too). Relying on the exception type is better, because it makes handling
of those exceptions easier (especially if they need to be dealt with at
different levels of the application). And just think about
internationalized error messages...
robert
Robert Klemme Guest
-
Gennady #4
Re: Raising Excepitons
It is also convenient to define your own exception, even without any
extra information besides the message, if you need to raise it in
several places. In the very least it removes the message duplication
and facilitates in debugging.
Gennady.
Sincerely,
Gennady Bystritsky
On Nov 12, 2003, at 8:04 PM, David Naseby wrote:
>>>> -----Original Message-----
>> From: John W. Long [mailto:ws@johnwlong.com]>>> When is it a good idea to subclass and create my own error
>> class?
> Your testing example was good, and similarly, it also aids in
> debugging down
> the line. For example, if you have a method that opens a file and
> manipulates the data, its generally a good idea to know if an exception
> coming out of that method is related to the file ops or due to some
> use of
> the standard library, or from a defined bad operation from your code
> (error
> condition). Defining a derived exception class is a bit safer for
> client
> code to handle, rather than just parsing the exception message.
>
> David
>
>
Gennady Guest



Reply With Quote

