Creating your own exceptions is easy:
MyError = Class.new(StandardError) raise MyError, "FOO environment variable not set" unless ENV['FOO'] system "open http://example.com/" + ENV['FOO']
Catching an exception in this block of code may not be acceptable in this case, because it seems that you are simply printing a message with it. As a rule, never raise an exception if you are not ready to end it. In other words, avoid using exceptions for expected conditions. If the program can continue without installing FOO, it would be better to just make the execution of the system operator conditional:
system("open http://example.com/" + ENV['FOO']) if ENV['FOO']
or
ENV['FOO'] && system("open http://example.com/" + ENV['FOO'])
source share