blob: 457f18d554bad31272c34318371940b13611148d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.util;
import org.osgi.framework.*;
import java.lang.Thread.*;
/**
* The only raison d'etre for this Activator is so that it would set a global
* exception handler. It doesn't export any services and neither it runs any
* iniitialization - all it does is call
* <tt>Thread.setUncaughtExceptionHandler()</tt>
*
* @author Emil Ivov
*/
public class UtilActivator
implements BundleActivator,
Thread.UncaughtExceptionHandler
{
private static final Logger logger
= Logger.getLogger(UtilActivator.class);
/**
* Calls <tt>Thread.setUncaughtExceptionHandler()</tt>
*
* @param context The execution context of the bundle being started
* (unused).
* @throws Exception If this method throws an exception, this bundle is
* marked as stopped and the Framework will remove this bundle's
* listeners, unregister all services registered by this bundle, and
* release all services used by this bundle.
*/
public void start(BundleContext context)
throws Exception
{
logger.trace("Setting default uncaught exception handler.");
Thread.setDefaultUncaughtExceptionHandler(this);
Thread.currentThread().setDefaultUncaughtExceptionHandler(this);
}
/**
* Method invoked when a thread would terminate due to the given uncaught
* exception. All we do here is simply log the exception using the system
* logger.
*
* <p>Any exception thrown by this method will be ignored by the
* Java Virtual Machine and thus won't screw our application.
*
* @param thread the thread
* @param exc the exception
*/
public void uncaughtException(Thread thread, Throwable exc)
{
logger.error("An uncaught exception occurred in thread="
+ thread
+ " and message was: "
+ exc.getMessage()
, exc);
}
/**
* Doesn't do anything.
*
* @param context The execution context of the bundle being stopped.
* @throws Exception If this method throws an exception, the bundle is
* still marked as stopped, and the Framework will remove the bundle's
* listeners, unregister all services registered by the bundle, and
* release all services used by the bundle.
*/
public void stop(BundleContext context)
throws Exception
{
}
}
|