You are here: Forums Ask a Rails expert Exception error code...
Posted in Forums : Ask a Rails expert
Authority 0
Posting Rating 0
Sign in to rate this post
|
Hello When I treat an Exception in my application I do this with the following code: def x
begin
...
rescue Exception => e
logger.error(e.message)
end “e.message” gives the error message. Is there a way to get the error code? Thanks |
Authority 12
Posting Rating 96
Sign in to rate this post
|
Hi Paulo, Ruby’s base Exception class ( http://www.ruby-doc.org/core/classes/Exception.html ) only has a ‘message’ property. In cases where a code is needed the original developer will have made a subclass of Exception which defines the extra fields needed. Your code can have multiple rescue clauses to handle this, for example
Jon |
Authority 12
Posting Rating 96
Sign in to rate this post
|
When an error occurs, the Ruby interpreter packages the error in an exception object. This object propagates back up the call stack until it reaches some code that explicitly declares it knows how to handle this particular type of exception. Exceptions that are never caught propagate through the call stack, ending up with an abnormal program termination; the stack trace is printed to stderr. This is opposed to returning error codes like shell scripts and C do, leading to less-nested statements, less spaghetti logic and simply better error handling. Go through this http://www.linuxjournal.com/article/4834 |
Ask a Rails expert : Get disk info
Ask a Rails expert : Problem with rails 2.1.0 & its older versions
Ask a Rails expert : How to test authentication and get the specific error using net:: http class
Ask a Rails expert : AJAX and set focus
Ask a Rails expert : How to use mephisto
Ask a Rails expert : Sanitizing html
Ask a Rails expert : First post, requesting sage perspective
Ask a Rails expert : How to use mephisto
Ask a Rails expert : will_paginate customization problem
Ask a Rails expert : BackgroundRB still wants 'development' environment...?