# Try catch for loading gems

**URL:** <https://www.ruby-forum.com/t/try-catch-for-loading-gems/73169>\
**Category:** Rails\
**Created:** [October 22, 2006, 2:14pm UTC](https://www.ruby-forum.com/t/try-catch-for-loading-gems/73169 "2006-10-22T14:14:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d07c76/32.png) [@nicken](https://www.ruby-forum.com/u/nicken)\
**Post date:** [October 22, 2006, 2:14pm UTC](https://www.ruby-forum.com/t/try-catch-for-loading-gems/73169/1 "2006-10-22T14:14:41Z")

</div>

Hey,

I have this in my environment.rb file for requiring gems

require ‘action\_mailer’  
require ‘sentry’  
require ‘money’  
require ‘active\_merchant’  
require ‘pdf/writer’  
require ‘pdf/simpletable’  
require ‘csv’  
require ‘tzinfo/timezone’  
require ‘TzForSelect’  
require ‘encryption’  
require ‘rexml/document’  
require ‘rubygems’  
require ‘RMagick’  
require ‘scoped\_access’

But when i do a clean install of my pc, i need to install these gems  
again. Sometimes i forget that 😛 And i get the project doesnt want to  
start. So i want something like this if it is possible. For each gem  
btw…

try  
require ‘sentry’  
catch  
put “The sentry gem must be installed”  
end

I dont know the code for this, and if it is even possible??

Can somebody help me?

Thx  
N.

---

<div class="post-metadata">

**Author:** ![nicken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d07c76/32.png) [@nicken](https://www.ruby-forum.com/u/nicken)\
**Post date:** [October 22, 2006, 2:48pm UTC](https://www.ruby-forum.com/t/try-catch-for-loading-gems/73169/2 "2006-10-22T14:48:43Z")

</div>

Try:

begin  
require “lib”  
rescue LoadError  
logger.error “lib gem must be installed”  
end

Another solution is to put all your installed gems in your vendor  
directory.

---

<div class="post-metadata">

**Author:** ![nicken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d07c76/32.png) [@nicken](https://www.ruby-forum.com/u/nicken)\
**Post date:** [October 22, 2006, 3:03pm UTC](https://www.ruby-forum.com/t/try-catch-for-loading-gems/73169/3 "2006-10-22T15:03:24Z")

</div>

Bruno C. wrote:

> Try:
> 
> begin  
> require “lib”  
> rescue LoadError  
> logger.error “lib gem must be installed”  
> end
> 
> Another solution is to put all your installed gems in your vendor  
> directory.

It worked!

Thx. 😉
