LAMW - ungraceful exit lazarus / 43-Android ---------------------------------------------------------------------- CC · 2019-06-30 18:08 Hi, A LAMW application exits without a beep  in a situation like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   aComponent:= nil;  aComponent.Tag:=1;  An android  application built with Delphi at least displays an access violation message. Maybe there is something to learn from Delphi here. Maybe the difference  is in the Java part ... An other related issue is that none of them actually executes the exception handling part of a try ..... except block in such a case. This makes proper exception handling impossible. These problems are so fundamental. Unhandled exceptions  can cause terrible user experience and lots  of bad user reviews. ---------------------------------------------------------------------- jmpessoa · 2019-06-30 19:45 There is a workaround here: "AppPascalLibExceptionHandlerDemo1" ---------------------------------------------------------------------- CC · 2019-07-01 09:11 jmpessoa, thanks for the tip, but unfortunately this does nor work for my original problem above (referencing a null pointer); ---------------------------------------------------------------------- CC · 2019-07-01 09:27 Wow, I assumed not handling the null pointer exception was an FPC/DELPHI issue, but it  turns out it is deeper than that: https://howtodoinjava.com/java/exception-handling/how-to-effectively- handle-nullpointerexception-in-java/ ---------------------------------------------------------------------- CC · 2019-07-01 09:37 So it basically says that  we need to check for null manually all the time.  The main point is to be able to catch the exceptions the developers missed in a graceful manner. What I would see as an accaptable solution is  to have  application level  exception handling for all the exceptions not dealt with so it could report a stacktrace to the developer and display a user friendly message to the user. Maybe something like  this can be the solution: Code: Java  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i public class BaseActivity extends Activity {    @Override    public void onCreate() {        super.onCreate();         final Thread.UncaughtExceptionHandler oldHandler =            Thread.getDefaultUncaughtExceptionHandler();         Thread.setDefaultUncaughtExceptionHandler(            new Thread.UncaughtExceptionHandler() {                @Override              public void uncaughtException(                    Thread paramThread,                    Throwable paramThrowable              ) {                    //Do your own error handling here                   if (oldHandler != null)                        oldHandler.uncaughtException(                            paramThread,                            paramThrowable                        ); //Delegates to Android's error handling                    else                      System.exit(2); //Prevents the service/app from freezing                }            });    }} ---------------------------------------------------------------------- CC · 2019-07-01 10:14 I will think this through, just thinking loudly here: Something like https://github.com/ACRA/acra can be one way to  go,  or something like this: Code: Java  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i public class CustomExceptionHandler implements UncaughtExceptionHandler {   private UncaughtExceptionHandler defaultUEH;     private String localPath;     private String url;     /*      * if any of the parameters is null, the respective functionality      * will not be used      */    public CustomExceptionHandler(String localPath, String url) {        this.localPath = localPath;        this.url = url;      this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();    }     public void uncaughtException(Thread t, Throwable e) {        String timestamp = TimestampFormatter.getInstance().getTimestamp();        final Writer result = new StringWriter();        final PrintWriter printWriter = new PrintWriter(result);        e.printStackTrace(printWriter);        String stacktrace = result.toString();        printWriter.close();        String filename = timestamp + ".stacktrace";         if (localPath != null) {          writeToFile(stacktrace, filename);        }        if (url != null) {            sendToServer(stacktrace, filename);        }         defaultUEH.uncaughtException(t, e);    }     private void writeToFile(String stacktrace, String filename) {        try {          BufferedWriter bos = new BufferedWriter(new FileWriter(                  localPath + "/" + filename));            bos.write(stacktrace);            bos.flush();            bos.close();        } catch (Exception e) {            e.printStackTrace();        }    }     private void sendToServer(String stacktrace, String filename) {        DefaultHttpClient httpClient = new DefaultHttpClient();        HttpPost httpPost = new HttpPost(url);        List nvps = new ArrayList();        nvps.add(new BasicNameValuePair("filename", filename));        nvps.add(new BasicNameValuePair("stacktrace", stacktrace));        try {          httpPost.setEntity(                    new UrlEncodedFormEntity(nvps, HTTP.UTF_8));            httpClient.execute(httpPost);        } catch (IOException e) {            e.printStackTrace();        }    }}