Ask a Question related to Ruby, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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
    4. 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...
    5. 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...
  3. #2

    Default Re: Raising Excepitons

    >-----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


    David Naseby Guest

  4. #3

    Default Re: Raising Excepitons


    "David Naseby" <david.naseby@eonesolutions.com.au> schrieb im Newsbeitrag
    news:C1B5ED61365AD511805500D0B7B697C633DAEF@sydeon e.eonesolutions.com.au...
    > >-----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.
    Not only is it "a bit safer" but it's much cleaner (and maybe faster,
    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

  5. #4

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139