Forum Xamarin Xamarin.Forms

No close application after of get exception of try catch

ElPiponElPipon COMember ✭✭
edited August 2017 in Xamarin.Forms

Hello guys.

i have a socket connection using try and catch, but after of show error message with catch my application is close automatically.

My code:

try
{
sockets = await Task.Run(() => sockets = new Socket("IP", PORT));
}
catch (SocketException ex)
{
Device.BeginInvokeOnMainThread(async() =>
{
await dialogservice.ShowMessage("Error", "Error in download: " + ex.Message + "In" +
": " + ex.Source + "or too: " + ex.LocalizedMessage);
});

        }

``
I need that my application dont close after of show message by catch. ¿Who know how can solve this?.

Posts

  • WarwenczackWarwenczack BRMember ✭✭

    instead of use the try catch, you can use status of the return, and depend of the status make some stuff or other...

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Your application crashed. If you want it to not close you need to debug it and figure out why it crashed. That's basic development. No magic bullet here. You have to do the job of developing your software.

    Just as an example:
    await dialogservice.ShowMessage("Error", "Error in download: " + ex.Message + "In" + ": " + ex.Source + "or too: " + ex.LocalizedMessage);
    What if dialogservice or ex.Source or ex.LocalizedMessage is null? You crash. And you aren't checking for nulls.
    What if dialogservice.ShowMessage thows an exception? You crash.

  • ElPiponElPipon COMember ✭✭
    edited August 2017

    Sorry, i after of look my code only i need use return after of show message.

  • JohnHardmanJohnHardman GBUniversity admin

    @ElPipon - Put a try/catch around the following line to see if that is throwing an exception (and if so, why):

    await dialogservice.ShowMessage("Error", "Error in download: " + ex.Message + "In" +
    ": " + ex.Source + "or too: " + ex.LocalizedMessage);

    You should also add unhandled exception handlers and/or support for HockeyApp or Mobile Center, so that you have some detail about exceptions that you have not caught elsewhere.

Sign In or Register to comment.