Using IRB from a script

I’d like to build a script that makes use of IRB for input and
evaluation.
Ideally, I’d also like to be able to capture exceptions raised from
expressions entered and handle them. Can anyone point me to some
resources
for doing this?

Thanks!

Justin