Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Ho can I stop he WindowsPhone Application in catch(){ } blocks ?
C#
try
{
    //Codes
}
catch (Exception)
{
    MessageBox.Show("An Error Has Occured , Please Try Again.");
    //ApplicationStop.
}
Posted
Comments
ct_12 3-Jan-13 8:05am    
I just want to Stop Program I mean I have 3 more methods after above method , when it goes to catch block I dont want it to go to the toher methods.
Olter 4-Jan-13 0:28am    
This question doesn't refer exactly to Windows Phone, you might have just used c# tag. I thought, you're asking about specific logic of Window Phone behavior. :) However, I hope, my answer will help you.

1 solution

What do you mean by "stop application"? Stop what: Navigation? All threads in app? Current method execution?

I suppose, you're talking about "continue working after an exception was thrown". In this case, you need only catch block, it will prevent your app from crashing. However, if you work in the Debug mode, you'll see the info about this error in a separate page, that's normal behaviour, it won't be visible in release app.

[updated]
If you want to prevent firing all code below the catch block, you should just call return in it.

i.e.

C#
catch
{
   // handling exception
   return;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900