I've created a bindings project, hooked everything up in my onCreate etc. Everything works except for unhandled exceptions. Let me elaborate on "Everything works" - I can see via crittercism's live stats page that there is indeed an app load, I can also send up "ManagedExceptions" using the "LogHandledException" interface.
I have implemented the ICritterCallback interface and the "CrashedOnLastLoad" boolean is always false. This is wierd cos I can see the app crashes.
I have used these 3 ways to try and get my logs sent to Crittercism. (All 3 crash the app)
Java exception
throw new Java.Lang.IllegalArgumentException("This is a test for critter");
Background exception
.Click += delegate { ThreadPool.QueueUserWorkItem(o => { throw new Exception("Crashed Background thread."); } ); };
Simple .net exception
throw new Exception("Crashed UI thread.");
None of the above are registering as crashes on the next load... weird right?
Maybe the .net runtime is swallowing all the unhandled exceptions then calling exit gracefully on dalvic's runtime... is this possible..?
As a hack for now im implementing the exception handlers for android as per this blog post then calling Crittercism.LogHandledException(Throwable.FromException(e.Exception)); from inside both the events.
It works, but im using Crittercism's handled exceptions for unhandled exceptions.. So when I want to send up real "HandledExceptions" they will be lost in the mess.
So is there any way to send an unhandled exception to Crittercism??
Or is there a way to simulate a crash on android from .net that will send it to Crittercism??
Any help would be much appreciated!
Cheers,
Sam
Co-founder of Crittercism here. We just released an official plugin for Xamarin which should automatically log javascript exceptions (and any other crashes) as unhandled exceptions so you won't run into this problem anymore. You can download the latest version from the Xamarin asset store here:
http://components.xamarin.com/view/crittercism
Related
I've encountered a situation where anything that runs in a coroutine (database queries, network requests or response processing) and fails at some point, simply crashes the app without any logs at all. Is it the expected behavior or do I have something misconfigured?
Here's a simple piece of code that reproduces the error.
Nothing changes with different Dispatchers.
This is the only output I'm getting, followed by app termination
And these are the dependencies I'm using, the latest version at the moment of writing.
It's also reproducing in a simple CLI app without the Android framework.
Edit: Just to make it clear. I'm not trying to see the Exceptions that I'm throwing. I'm trying to get some output when my app crashes because of an unknown reason.
Edit2: To add some clarity, here is another example of the situation without any "throw" statements.
Since the exception in happening inside the coroutine, it makes sense to find it there also. Just surround it with try/catch and you will see the magic:
GlobalScope.launch{
try{
print("Your printing message")
throw Exception("Message here")
}catch(exception: Exception){
exception.printStacktrace()
}
}
I am trying to debug a Nativescript app for Android and I have noticed that it no longer prints Syntax errors with their corresponding line and col. numbers, not even console.log statements. How can I enable this feature again? The command I use to launch the app is tns run android. I am using Nativescript version 2.5.2. The VSCode plugin doesn't work either as it ignores any breakpoint I place, and also the console doesn't show any errors. What can I do?
Edit:
It appears that only console.error() statements get printed.
After tinkering a lot with different kinds of constructions and by researching more into how Nativescript relates to regular browser JS, I found out that the problem lies in the use of Promises, which in case of errors defer the execution to the catch() method, but unlike any other regular programming language, "unhandled" rejected results within promises won't raise any kind of exception; which means that, basically, for any promise you invoke in your code, you should have a chained catch() method call so you effectively catch any errors your promises might produce. This also applies to promises which involve navigation, where stuff gets a lot trickier: You might think the next view (say, view.js) will have a call stack on its own and produce an unhandled exception at code that's not even inside a promise in there, but that's not the case: An exception produced at view.js will get captured by the catch() method of the promise within which you started the navigation, and any subsequent promises must have their own catch() method calls because errors won't get bubbled up to the previous view. I can think of many other troublesome constructions but I hope the important bit stays clear: always chain a catch call on any and all promises.
I got an android app where I set a global exception handler as described here:
Using Global Exception Handling on android
When I'm forcing an exception then I see that it is catched by the handler.
But from time to time I'm still experiencing device freezes when running the app.
The app uses a lot of different threads. But as far as I understand, this should have no influence.
Are there some known limitations on android regarding global exception handling, where exception are not handled by the global handler?
Thanks
My Android app uses the AWS Java SDK for uploading user photos to S3.
Whenever a user's phone's clock is 'skewed', this causes all transfers to fail. This is a well documented aspect of S3:
http://aws.amazon.com/articles/1109?_encoding=UTF8&jiveRedirect=1#04
It appears that the upstream S3 service reports this error quite clearly:
HTTP Status Code: 403 Forbidden
Error Code: RequestTimeToo-Skewed
Description: The difference between the request time and the server's
time is too large.
However when using the Java SDK, it seems as if the informative 403 code is lost ... and I have only an opaque "TransferState.Failed" to go by (which incidentally is the same error if internet connectivity is lost, if it times out, etc...).
As far as I can tell from the docs:
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferProgress.html
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/Transfer.TransferState.html
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/Upload.html
There is no way to get the additional "RequestTimeToo-Skewed" metadata about a transfer failure.
Am I missing it? Is there any way to get additional error information when an S3 transfer fails using Amazon's Java SDK?
UPDATE #1:
A commenter kindly highlighted that I should clarity two points:
I am actually using the AWS SDK for Android (which seems very similar to the Java SDK, but is nonetheless distinct)
I am using the TransferManager class to perform my upload. Apparently, this is a high-level class that wraps the lower-level AmazonS3Client ... and this lower-level class should expose the error reporting I need, but I am still investigating the exact tradeoffs involved between TransferManager and AmazonS3Client. As far as I can tell, there is no way to get progress information via the (synchronous) AmazonS3Client.putObjectRequest which would be a blocker for me...
UPDATE #2:
My sincere thanks to Jason (of the AWS SDK team) for stopping by and helping me out here. The important information is, indeed, available as properties on an AmazonS3Exception if you use certain methods. The docs had originally confused me and I thought that a manual Thread.sleep() loop was required to poll status (and thus I could not leverage waitForCompletion or waitForException), but if you use ProgressListener on PutObjectRequest you can get full progress callbacks and the error-fidelity of AmazonS3Exception.
these two methods should help you out:
Transfer.waitForCompletion()
Transfer.waitForException()
If you detect that your transfer has failed based on a transfer progress event, you can simply call Transfer.waitForException() to be returned the exception that occurred. That exception will be an AmazonServiceException in this case, with all of the info that you need to see that the real problem was a clock skew issue.
Alternatively, the Transfer.waitForCompletion() method will unwrap the original exception from an ExecutionException and directly throw the original exception, just as if it'd all been happening on one thread. This might be a more convenient approach if you want to use a catch blocks to catch different types of errors cleanly and elegantly.
I disagree that the "catch Exception" block is "brutally broad". The point of that code is to catch any error that happens, mark the transfer as failed and rethrow the error so that the application code can know about it. If it were less broad, then that's exactly the case where exceptions could sneak through and transfer progress wouldn't be updated correctly and would be out of sync with reality.
Give those two methods and shot and let us know if that helps!
Well, I have debugged Amazon's SDK and I'm sorry to say that this information is being swallowed internally. Perhaps I will try to submit a patch.
Details: an AmazonS3Exception is being thrown internally which does in fact accurately report this exact error scenario, but a brutally broad try catch ( Exception e ) consumes it and washes away the specificity.
Here is the guilty try-catch:
https://github.com/aws/aws-sdk-java/blob/master/src/main/java/com/amazonaws/services/s3/transfer/internal/UploadMonitor.java#L145
Here is a screenshot showing that an AmazonS3Exception is correctly thrown with the right info...
What is the usual way on Android to stop my application if it has reached an unrecoverable error.
finish() will not do it, since it wont stop any running services or threads. Furthermore I would like to inform the user what has happend and please him to send an error log.
As far as I googled, it seems like there is no way to close my application and open a special crashreport activity or something else to show the user whats going on or send a crash log.
I think you should throw unhandled runtime exception. In such case android will kill all your process. Also I suggest you to use ACRA. This library will help you to get crash report (via email, google docs, etс.) and it can show customizable error dialog to a user.
You should check this out. This could be your solution.
ACRA
Check the basic setup guide to start using the library. ACRA - Basic Setup
While ACRA is an okay solution, if you want to implement your own logging of unhandled exceptions try Thread.setDefaultUncaughtExceptionHandler(). That way you can get any exceptions that are thrown and not caught, and log them the way you like. You need to implement Thread.UncaughtExceptionHandler and pass it to that method.
With an Activity, it would look something like this in onCreate():
getMainLooper().getThread().setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());