Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8507205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:48:16+00:00 2026-06-11T02:48:16+00:00

I’m trying to hook up a global exception handler using NSSetUncaughtExceptionHandler in a Rubymotion

  • 0

I’m trying to hook up a global exception handler using NSSetUncaughtExceptionHandler in a Rubymotion app. And I can’t figure out how to do it, probably I’m using Rubymotion function pointer syntax incorrectly.

In application(application, didFinishLaunchingWithOptions:launchOptions) I have:

NSSetUncaughtExceptionHandler nil do |exception|
  NSLog "exception handler block"
  applicationFailedWithException(exception)
end

And the handler (which is never called):

def applicationFailedWithException(exception)
  NSLog "applicationFailedWithException"
end

Then, in runtime, when some NoMethodError happens somewhere neither the exception handler block, neither the handler method are called. I’ve tried both in the Simulator and on the device — no success.

P.S. Is there a way to get the ruby methods stack in the crash log, the last application method in the crash log is always the rb_rb2oc_exc_handler instead of the app-specific method, and that’s weird.

Thanks

Update 2015

It seems that with the newer versions of the Rubymotion you have to save a references to the handler in an instance variable, otherwise it will not work. So it should look like:

def application(application, didFinishLaunchingWithOptions:launchOptions)
  @exceptionHandler = lambda { |exception| uncaughtExceptionHandler(exception) }

  # or you can use a method reference, which is the same
  # @exceptionHandler = method :uncaughtExceptionHandler

  NSSetUncaughtExceptionHandler @exceptionHandler

  ...
end

def uncaughtExceptionHandler(exception)
  # log it or send it to crashlytics / flurry / whatever
  NSLog "Fatal exception catched\nName: #{exception.name}\nReason: # {exception.reason}\nInfo#{exception.userInfo}"
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:48:18+00:00Added an answer on June 11, 2026 at 2:48 am

    To get this to work, I had to assign a block to a variable, then use that variable:

    handler = lambda do |exception|
      NSLog "Exception Name: #{exception.name}"
    end
    NSSetUncaughtExceptionHandler(handler)
    

    If I then punch in something like NSException.raise("test", format: "test") in the REPL, I’ll see NSLog do it’s thing:

    2012-09-11 09:33:05.949 exc[14723:c07] Exception Name: test
    2012-09-11 09:33:05.950 exc[14723:c07] *** Terminating app due to uncaught exception 'test', reason: 'test'
    *** First throw call stack:
    (0x1647022 0x22bcd6 0x15efa48 0x15ef9b9 0x8f00743 0xe3c0c 0x8f0031a 0x8f000ad 0xd4c9fa2 0x259e8d9 0x259f509 0x157e803 0x157dd84 0x157dc9b 0x261f7d8 0x261f88a 0x563626 0x25d0 0x23b5)
    terminate called throwing an exception%                                                                                 
    

    Theoretically, you should be able to nest the lambda directly as the parameter rather than assigning it to a variable first, but I don’t think RubyMotion properly retains the block and the application crashes without error if you try it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.