Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

How to catch platform specific errors in PCL Xamarin Forms

$
0
0

Hi there,
I am developing a CROSS PLATFORM mobile that works on ANDROID and iPhone.
My project structure is
1. PCL
2. Android
3. iOS

I have a screen(XAML) where I upload a photo to an Image.
On an Android phone the photo seems to be very large and I get OUT OF MEMORY exception with the below code in PCL project.

    public async void SelectProfileImage(object sender, EventArgs e)
    {
            try
            {
                    IMediaPicker mediaPicker = DependencyService.Get();
                    await mediaPicker.SelectPhotoAsync(new CameraMediaStorageOptions()
                    {
                    DefaultCamera = App.Singleton.User.camera_direction == 0 ? CameraDevice.Front : CameraDevice.Rear,
                    MaxPixelDimension = 400
                    }).ContinueWith(async (t) => {
                    if(!t.IsFaulted && !t.IsCanceled){
                    media = t.Result;
                    eventImagePath = media.Path;
                    Device.BeginInvokeOnMainThread( () => {
                            Debug.WriteLine("Selected event media path is " + media.Path);
                            eventImageChangedWhileEditing = true;
                            ImageCircle.Forms.Plugin.Abstractions.CircleImage eventImage = contentViewWizard.FindByName<ImageCircle.Forms.Plugin.Abstractions.CircleImage> ("imgEventImage");
                            try
                            {
                                    eventImage.Source = ImageSource.FromStream(() => media.Source); // throws java.Lang.Error for very big images. This is not caught by the CATCH statement below.
                            }
                            catch(Exception ex1)
                            {
                                    Debugger.Break ();
                                    // Debug.WriteLine (ex1.Message);
                                    // Debug.WriteLine (ex1.StackTrace);
                            }
                    });
                    }
                    });
            }
            catch (Exception ex)
            {
                    Debugger.Break ();
                    Debug.WriteLine (ex.Message);
                    Debug.WriteLine (ex.StackTrace);
            }
    }

When such platform specific errors (not exceptions - I looked on internet and some people told that the OUT OF MEMORY is an error , not an exception. It is a THROWABLE in Android) occur how to catch them in PCL project?
Many thanks,
Venkat V R


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>