You are here: Forums Ask a Rails expert Exception error code...
Posted in Forums : Ask a Rails expert
Authority 0
Posting Rating 15
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 98
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 : HTML to XML ---> get title & description
Ask a Rails expert : Accessing controller actions from scripted page?
Ask a Rails expert : seledted option for select_tag
Ask a Rails expert : Merging fields from two tables into one, including duplicates
Ask a Rails expert : saving has_many :through
Ask a Rails expert : Use Rails to develop sites for both Designer and Programmer
Ask a Rails expert : Rails+RS232
Ask a Rails expert : Is this a good way to add Admin section
Ask a Rails expert : RSS feed maker in rails 2.1
Ask a Rails expert : Syncing with ugly legacy databases