global catch all java Exceptions in JRuby Sinatra app - jruby

Im implementing a rest api with sinatra and jruby. The application domain is implemented in java. I have not figured out how to catch all exceptions thrown by the java layer in Sinatra. the global 'error do ... end' does not catch my java exception.
Any hints would be appreciated
/floda

Related

After install the NuGet package sqlite-net-pcl, JsonSerializer.Serialize raised an exception (Xamarin)

To store JSON data, I installed the NuGet package sqlite-net-pcl for the Xamarin project. Before install the package sqlite-net-pcl, everything is working normally and I didn't change the contents of code. No ideas what wrong with the setting. Please comment how to solve the problem?
Installed the NuGet package sqlite-net-pcl and execute Serialize, an exception is raised.
execute to serialize an object to JSON,
// route is an object
JsonSerializer.Serialize(route);
and exception is raised unexpectedly.
catch (Exception)
{
// exception
}

Castle Windsor container.Resolve produces null reference exception

In my Visual Studio environment my project that uses Castle Windsor dependency injection runs correctly.
When deployed to a target environment however, it fails to start. Capturing exceptions has show this issue:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
at My.MyService..ctor()
at My.Program.Main(System.String[])
I checked registrations but everything seems OK.
Any ideas?
It turned out that my installer failed to deploy some of the dll's. Once that was fixed, the above exception disappeared.
Takeaway: when a type fails to load dependency resolution, you receive a NullReferenceExecption. It'd be more friendly to get a TypeLoadException as the framework does when a library is not available.

How to catch any exception in Anypoint studio?

I want to specify a global catch exception strategy that would catch any exception a mule app throws. Please help me.

RESTEasy gives NoClassDefFoundError for HeaderParameterParser

I have written simple RESTEasy Hello World web-service. It used to work just fine when invoked from IE or from within Eclipse(RAD), but when I hit it from Google Chrome, it used give Exception saying.
com.ibm.ws.webcontainer.servlet.ServletWrapper service Uncaught service() exception thrown by servlet RestEasy: java.lang.NoClassDefFoundError: org/jboss/resteasy/util/HeaderParameterParser
at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.parse(MediaTypeHeaderDelegate.java:57)
at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.fromString(MediaTypeHeaderDelegate.java:18)
at javax.ws.rs.core.MediaType.valueOf(MediaType.java:150)
at org.jboss.resteasy.util.MediaTypeHelper.parseHeader(MediaTypeHelper.java:203)
at org.jboss.resteasy.plugins.server.servlet.ServletUtil.extractAccepts(ServletUtil.java:120)
at org.jboss.resteasy.plugins.server.servlet.ServletUtil.extractHttpHeaders(ServletUtil.java:83)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:186)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1224)
But now this Exception is occurring in all the cases.
I am sure that the jar file containing HeaderParameterParser class which is restreasy-jaxrs2.2.3.GA.jar is on the classpath.
I am using
RESTEasy 2.2.3.GA(also tried with 3.o.1Final).
Websphere Application Server v8.0
RAD 8.0
Maven

how can I be notified when a bundle throws an exception in osgi runtime? (equinox helios)

If a bundle throws an exception in osgi, the stack-trace is printed on the osgi console. I want to be notified if a bundle throws an exception. I thought using osgi logging service could help about it. However I could not get it to work under Helios.
The question is how can I be notified if a bundle throws an exception in osgi Helios.
Or if osgi logging does the work, how can I get osgi logging to work in Helios? As much as I googled, there is apparently no implementation of osgi loggin service currently integrated in helios. I downloaded the equinox skd 3.6 from eclipse site that contains the bundle org.eclipse.equinox.log, however I could add it as dependency to my plugins, or install it in the osgi runtime.
Any help is really appreciated.
A bundle can only throw an exception when it is invoked. This nearly always when some other bundle invoked one of your published services, or because the bundle received a callback from the framework such as BundleActivator.start().
In the first case, OSGi has absolutely no way to know that an exception happened! Service invocations are direct method calls between two objects, and are not brokered or proxied by the OSGi framework. Therefore if you want to find out about the exception, you must catch it in the calling code.
In the second case, callbacks happen because some bundle caused them to happen. For example, a bundle will be started because some other bundle called Bundle.start(). In this case, an exception thrown from the BundleActivator.start() method would be wrapped in a BundleException that could be caught by the calling code.
So it's really all down to your code, unless you have some third-party bundles that invoke your services or start/stop your bundles (e.g. a web console, or a shell like GoGo). In this case it's down to the third party code. In most cases they should send messages to the LogService, so you should install the log bundle into your framework.
You said that you couldn't install the log bundle, but you didn't say why it failed, what the error message was etc! This kind if information is important if you want help resolving the problem.
You could try Pax Logging and a custom Log4J appender - Pax Logging provides implementations of the OSGi LogService etc as well as wrappers for common logging frameworks.
Do you want to do this purely to log/notify exceptions, or is there some other reason? An UncaughtExceptionHandler might be what you want if it's a case of managing your own or wrapped code.