MrJaba / simple-exception-definition
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
commit 0f384d8f250bc38b5d11916d10b5c7ea24b961dc
tree dae2428e3d495a35150cc9c3d7f2c5e999803b18
parent fe4882e3591cf6ed79a9ec5b82ee9ac6caa99311
tree dae2428e3d495a35150cc9c3d7f2c5e999803b18
parent fe4882e3591cf6ed79a9ec5b82ee9ac6caa99311
| name | age | message | |
|---|---|---|---|
| |
.gitignore | ||
| |
MIT-LICENSE | ||
| |
README | ||
| |
Rakefile | ||
| |
init.rb | ||
| |
install.rb | ||
| |
lib/ | ||
| |
simple-exception-definition.gemspec | ||
| |
tasks/ | ||
| |
test/ | ||
| |
uninstall.rb |
README
SimpleExceptionDefinition
=========================
I've found in a few projects I define quite a few custom exceptions, I prefer them as they often express the intent of
the exception much more clearly and can increase readability. However, most follow a very similar pattern, which isn't
very DRY at all, so this plugin goes a little way to help with that.
Example
=======
class Example
define_exception :my_custom_exception
def rescue_bad_things
begin
do_bad_things
rescue MyCustomException => e
logger.error(e.message)
end
end
def do_bad_things
raise MyCustomException.new("Error message")
end
end
instead of:
class Example
...
end
class MyCustomException < StandardError
def initialize( error_message, object )
@message = error_message
@object = object
end
def message
@message
end
end
Saves a few lines at least :)
Thanks
======
Thanks to Simon Jefford for the gemified version and rakefile.
Copyright (c) 2008 [Tom Crinson], released under the MIT license

