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 8143575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:09:18+00:00 2026-06-06T13:09:18+00:00

In my onCreate() I set an UncaughtException handler as follows: Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override

  • 0

In my onCreate() I set an UncaughtException handler as follows:

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
    @Override
    public void uncaughtException(Thread thread, Throwable throwable) {
       Log.e(getMethodName(2), "uncaughtException", throwable);
       android.os.Process.killProcess(android.os.Process.myPid());
    }
});

It works OK, but I would like to get back the system’s default behavior of displaying the force-close dialog to the user.

If I try to replace the KillProcess() call with a throw throwable the compiler complains that I need to surround it with a try/catch.

If I surround it with a try/catch:

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
    @Override
    public void uncaughtException(Thread thread, Throwable throwable) {
        try {
            Log.e(getMethodName(2), "uncaughtException", throwable);
            throw throwable;
        }
        catch (Exception e) {           
        }
        finally {               
        }
    }
});

The compiler still complains that throw throwable needs to be surrounded with a try/catch.

How do I re-throw that throwable? Such that except for that informative Log.e() the system behaves exactly as before: As is I never set a default UncaughtException handler.

  • 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-06T13:09:19+00:00Added an answer on June 6, 2026 at 1:09 pm

    Try:

    public class CustomExceptionHandler implements UncaughtExceptionHandler {
    
        private UncaughtExceptionHandler defaultUEH;
    
        public CustomExceptionHandler() {
            this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
        }
    
        public void uncaughtException(Thread t, Throwable e) {
            Log.e("Tag", "uncaughtException", throwable);
            defaultUEH.uncaughtException(t, e);
        }
    }
    

    and then
    Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler());

    Adapted from this answer.

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

Sidebar

Related Questions

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); loadData(); setContentView(R.layout.preload); Thread thread = new Thread() {
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txtUserName=(EditText)this.findViewById(R.id.txtUname); txtPassword=(EditText)this.findViewById(R.id.txtPwd); btnLogin=(Button)this.findViewById(R.id.btnLogin); Button btnLogin=(Button)this.findViewById(R.id.Button01); btnLogin.setOnClickListener(new
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txtUserName=(EditText)this.findViewById(R.id.txtUname); txtPassword=(EditText)this.findViewById(R.id.txtPwd); btnLogin=(Button)this.findViewById(R.id.btnLogin); btnLogin=(Button)this.findViewById(R.id.btnLogin); btnLogin.setOnClickListener(new OnClickListener()
@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.screenlocked); //Retrieve stored ID final String STORAGE =
I have using following code to set a thread on button action. public void
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Typeface font = Typeface.createFromAsset( getAssets(), DejaVuSans.ttf); setListAdapter(new ArrayAdapter<String>(this,
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initControls(); } I'm a noob android coder.
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.uniqueid); simID = (TextView) findViewById(R.id.text2); simIMSI = getSubscriberId().toString();
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lView = (ListView) findViewById(R.id.list1); PackageManager pm =
I have a Timer in my onCreate(), it should set a new text when

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.