How to treat unhandled exceptions? (Terminate the application vs. Keep it alive)ELMAH - Where does it fit...

Novel with a mix of real world and gods

Can digital computers understand infinity?

Why was the wedding ring missing during the twist of The Sixth Sense

Who is Sifter, and what is "the so-called Sifter flare"?

How to see time in ~/.bash_history file

How does Firefox know my ISP login page?

Advisor asked my whole slide presentation so she could give the presentation at international conference

2 Guards, 3 Keys, 2 Locks

How to give a rationality-inducing drug to an entire software company?

When did 5 foot squares become standard in D&D?

"A tin of biscuits" vs "A biscuit tin"

How can I turn on Adventure Sync?

What is the "Applicable country" field on the Icelandair check-in form?

Is there a push, in the United States, to use gender-neutral language and gender pronouns (when they are given)?

Treatment of large data sets (>1M) in standard objects

What does すきすき mean here?

Do businesses save their customers' credit card information until the payment is finalized?

"inuendo" in a piano score

How to protect my Wi-Fi password from being displayed by Android phones when sharing it with QR code?

The travel to a friend

Disordered Cryptic Orders

Is Schrodinger's Cat itself an observer?

Why is technology bad for children?

Should I avoid "big words" when writing to a younger audience?



How to treat unhandled exceptions? (Terminate the application vs. Keep it alive)


ELMAH - Where does it fit right…?WCF Keep Alive: Whether to disable keepAliveEnabledDoes this violate the using exceptions for flow control “rule”?We need a custom strategy for collecting unhandled application exceptions. What are our options?Using Statement lambda in exception handlingHow to handle exceptions that get absorbed by a 3rd party library?Throwing exceptions in application configuration providersHandling exception types according to the current “layer” of appplicationBest practices for handling application specific exceptions?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}








3

















What is best practice when a unhandled exceptions occurs in a desktop application?



I was thinking about to show a message to the user, so that he can contact support. I would recommend to the user to restart the application, but not force it. Similar to what is discussed here: ux.stackexchange.com - What's the best way to handle unexpected application errors?



The project is a .NET WPF application, so the described proposal could look like this (Note that this is a simplified example. Probably it would make sense to hide the exception details until the user click on "Show Details" and provide some functionality to easily report the error):



public partial class App : Application
{
public App()
{
DispatcherUnhandledException += OnDispatcherUnhandledException;
}

private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
LogError(e.Exception);
MessageBoxResult result = MessageBox.Show(
$"Please help us fix it and contact support@example.com. Exception details: {e.Exception}" +
"We recommend to restart the application. " +
"Do you want to stop the application now? (Warning: Unsaved data gets lost).",
"Unexpected error occured.", MessageBoxButton.YesNo);

// Setting 'Handled' to 'true' will prevent the application from terminating.
e.Handled = result == MessageBoxResult.No;
}

private void LogError(Exception ex)
{
// Log to a log file...
}
}


In the implementation (Commands of ViewModels or event handler of external events) I would then only catch the specific exogenous exception and let all other exceptions (boneheaded and unknown exceptions) bubble up to the "Last resort handler" described above. For a definition of boneheaded and exogenous exceptions have a look at: Eric Lippert - Vexing exceptions



Does it make sense to let the user decide if the application should be terminated?
When the application is terminated, then you for sure have no inconsistent state... On the other hand the user may loose unsaved data or is not able to stop any started external process anymore until the application is restarted.



Or is the decision if you should terminate the application on unhandled exceptions depending of the type of application you are writting? Is it just a trade off between "robustness" vs. "correctness" like described in Code Complete, Second Edition



To give you some context what kind of application we are talking about:
The application is mainly used to control chemical lab instruments and show the measured results to the user. To do so the WPF applications communicates with some services (local and remote services). The WPF application does not communicate directly with the instruments.










share|improve this question
























  • 3





    If you didn't expect an exception, how can you be sure the application can safely keep plodding on?

    – Deduplicator
    8 hours ago











  • @Deduplicator: Of course, you can't be sure. Like already written as comment to Matthew's answer: "Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?"

    – Jonas Benz
    8 hours ago




















3

















What is best practice when a unhandled exceptions occurs in a desktop application?



I was thinking about to show a message to the user, so that he can contact support. I would recommend to the user to restart the application, but not force it. Similar to what is discussed here: ux.stackexchange.com - What's the best way to handle unexpected application errors?



The project is a .NET WPF application, so the described proposal could look like this (Note that this is a simplified example. Probably it would make sense to hide the exception details until the user click on "Show Details" and provide some functionality to easily report the error):



public partial class App : Application
{
public App()
{
DispatcherUnhandledException += OnDispatcherUnhandledException;
}

private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
LogError(e.Exception);
MessageBoxResult result = MessageBox.Show(
$"Please help us fix it and contact support@example.com. Exception details: {e.Exception}" +
"We recommend to restart the application. " +
"Do you want to stop the application now? (Warning: Unsaved data gets lost).",
"Unexpected error occured.", MessageBoxButton.YesNo);

// Setting 'Handled' to 'true' will prevent the application from terminating.
e.Handled = result == MessageBoxResult.No;
}

private void LogError(Exception ex)
{
// Log to a log file...
}
}


In the implementation (Commands of ViewModels or event handler of external events) I would then only catch the specific exogenous exception and let all other exceptions (boneheaded and unknown exceptions) bubble up to the "Last resort handler" described above. For a definition of boneheaded and exogenous exceptions have a look at: Eric Lippert - Vexing exceptions



Does it make sense to let the user decide if the application should be terminated?
When the application is terminated, then you for sure have no inconsistent state... On the other hand the user may loose unsaved data or is not able to stop any started external process anymore until the application is restarted.



Or is the decision if you should terminate the application on unhandled exceptions depending of the type of application you are writting? Is it just a trade off between "robustness" vs. "correctness" like described in Code Complete, Second Edition



To give you some context what kind of application we are talking about:
The application is mainly used to control chemical lab instruments and show the measured results to the user. To do so the WPF applications communicates with some services (local and remote services). The WPF application does not communicate directly with the instruments.










share|improve this question
























  • 3





    If you didn't expect an exception, how can you be sure the application can safely keep plodding on?

    – Deduplicator
    8 hours ago











  • @Deduplicator: Of course, you can't be sure. Like already written as comment to Matthew's answer: "Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?"

    – Jonas Benz
    8 hours ago
















3












3








3








What is best practice when a unhandled exceptions occurs in a desktop application?



I was thinking about to show a message to the user, so that he can contact support. I would recommend to the user to restart the application, but not force it. Similar to what is discussed here: ux.stackexchange.com - What's the best way to handle unexpected application errors?



The project is a .NET WPF application, so the described proposal could look like this (Note that this is a simplified example. Probably it would make sense to hide the exception details until the user click on "Show Details" and provide some functionality to easily report the error):



public partial class App : Application
{
public App()
{
DispatcherUnhandledException += OnDispatcherUnhandledException;
}

private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
LogError(e.Exception);
MessageBoxResult result = MessageBox.Show(
$"Please help us fix it and contact support@example.com. Exception details: {e.Exception}" +
"We recommend to restart the application. " +
"Do you want to stop the application now? (Warning: Unsaved data gets lost).",
"Unexpected error occured.", MessageBoxButton.YesNo);

// Setting 'Handled' to 'true' will prevent the application from terminating.
e.Handled = result == MessageBoxResult.No;
}

private void LogError(Exception ex)
{
// Log to a log file...
}
}


In the implementation (Commands of ViewModels or event handler of external events) I would then only catch the specific exogenous exception and let all other exceptions (boneheaded and unknown exceptions) bubble up to the "Last resort handler" described above. For a definition of boneheaded and exogenous exceptions have a look at: Eric Lippert - Vexing exceptions



Does it make sense to let the user decide if the application should be terminated?
When the application is terminated, then you for sure have no inconsistent state... On the other hand the user may loose unsaved data or is not able to stop any started external process anymore until the application is restarted.



Or is the decision if you should terminate the application on unhandled exceptions depending of the type of application you are writting? Is it just a trade off between "robustness" vs. "correctness" like described in Code Complete, Second Edition



To give you some context what kind of application we are talking about:
The application is mainly used to control chemical lab instruments and show the measured results to the user. To do so the WPF applications communicates with some services (local and remote services). The WPF application does not communicate directly with the instruments.










share|improve this question
















What is best practice when a unhandled exceptions occurs in a desktop application?



I was thinking about to show a message to the user, so that he can contact support. I would recommend to the user to restart the application, but not force it. Similar to what is discussed here: ux.stackexchange.com - What's the best way to handle unexpected application errors?



The project is a .NET WPF application, so the described proposal could look like this (Note that this is a simplified example. Probably it would make sense to hide the exception details until the user click on "Show Details" and provide some functionality to easily report the error):



public partial class App : Application
{
public App()
{
DispatcherUnhandledException += OnDispatcherUnhandledException;
}

private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
LogError(e.Exception);
MessageBoxResult result = MessageBox.Show(
$"Please help us fix it and contact support@example.com. Exception details: {e.Exception}" +
"We recommend to restart the application. " +
"Do you want to stop the application now? (Warning: Unsaved data gets lost).",
"Unexpected error occured.", MessageBoxButton.YesNo);

// Setting 'Handled' to 'true' will prevent the application from terminating.
e.Handled = result == MessageBoxResult.No;
}

private void LogError(Exception ex)
{
// Log to a log file...
}
}


In the implementation (Commands of ViewModels or event handler of external events) I would then only catch the specific exogenous exception and let all other exceptions (boneheaded and unknown exceptions) bubble up to the "Last resort handler" described above. For a definition of boneheaded and exogenous exceptions have a look at: Eric Lippert - Vexing exceptions



Does it make sense to let the user decide if the application should be terminated?
When the application is terminated, then you for sure have no inconsistent state... On the other hand the user may loose unsaved data or is not able to stop any started external process anymore until the application is restarted.



Or is the decision if you should terminate the application on unhandled exceptions depending of the type of application you are writting? Is it just a trade off between "robustness" vs. "correctness" like described in Code Complete, Second Edition



To give you some context what kind of application we are talking about:
The application is mainly used to control chemical lab instruments and show the measured results to the user. To do so the WPF applications communicates with some services (local and remote services). The WPF application does not communicate directly with the instruments.







c# architecture .net exceptions fail-fast






share|improve this question















share|improve this question













share|improve this question




share|improve this question



share|improve this question








edited 8 hours ago









Laiv

8,5361 gold badge15 silver badges45 bronze badges




8,5361 gold badge15 silver badges45 bronze badges










asked 9 hours ago









Jonas BenzJonas Benz

1293 bronze badges




1293 bronze badges











  • 3





    If you didn't expect an exception, how can you be sure the application can safely keep plodding on?

    – Deduplicator
    8 hours ago











  • @Deduplicator: Of course, you can't be sure. Like already written as comment to Matthew's answer: "Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?"

    – Jonas Benz
    8 hours ago
















  • 3





    If you didn't expect an exception, how can you be sure the application can safely keep plodding on?

    – Deduplicator
    8 hours ago











  • @Deduplicator: Of course, you can't be sure. Like already written as comment to Matthew's answer: "Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?"

    – Jonas Benz
    8 hours ago










3




3





If you didn't expect an exception, how can you be sure the application can safely keep plodding on?

– Deduplicator
8 hours ago





If you didn't expect an exception, how can you be sure the application can safely keep plodding on?

– Deduplicator
8 hours ago













@Deduplicator: Of course, you can't be sure. Like already written as comment to Matthew's answer: "Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?"

– Jonas Benz
8 hours ago







@Deduplicator: Of course, you can't be sure. Like already written as comment to Matthew's answer: "Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?"

– Jonas Benz
8 hours ago












3 Answers
3






active

oldest

votes


















5


















It depends to some extent on the application you're developing but in general, I'd say that if your application encounters an unhandled exception, you need to terminate it.



Why?



Because you can no longer have any confidence in the state of the application.



Definitely, provide a helpful message to the user, but you should ultimately terminate the application.



Edit having looked at the context, I would definitely want the application to terminate. You do not want software running in a lab to produce corrupt output and since you didn't think to handle the exception, you have no idea why it was thrown and what is happening.






share|improve this answer





























  • I tried to add some context information about the application in the last part.

    – Jonas Benz
    8 hours ago











  • Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?

    – Jonas Benz
    8 hours ago











  • @JonasBenz Isn't it better for the user if he is able to save before he restarts the application? Yes, but how do you know if the data the user would be saving is valid and not corrupt? At this point, you've got an unexpected exception and you really don't know why. Your safest path, albeit annoying to the user, is to terminate the application. If you're concerned about the user saving work, you would employ a constant-saving strategy. Again, it all depends on the application you're writing.

    – Matthew
    7 hours ago













  • I agree that terminating is the safest solution. Therefore I would also suggest it in the error message (and do it, if the user not explicitly wants to keep it alive). But why not let the user decide? You don't know what does the bigger harm. A constant-saving strategy is not an option because the user has to enter a "reason for change" on every save. It is not only about saving... Maybe he want to stop an instrument in an error case.

    – Jonas Benz
    7 hours ago











  • The .NET framework seems to do something similar and asks the user in some cases: “Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.” Can't you argue the same way here? Why is there a "Continue" button?

    – Jonas Benz
    7 hours ago



















5


















You have to expect your program to terminate for more reasons than just an unhandled exception anyway, like a power failure, or a different background process which crashes the whole system. Therefore I would recommend to terminate and restart the application, but with some measures to mitigate the consequences of such a restart and minimize the possible data loss.



Start with analysing the following points:




  • how much data can actually get lost in case of a program termination?


  • how severe is such a loss really for the user? Can the lost data reconstructed in less than 5 minutes, or are we talking about losing a days work?


  • how much effort it is for you to implement some "intermediate backup" strategy (which saves not to the data pool where, as you wrote, the user would have to enter a change reason, but to something like a temporary file, which may be reloaded after a program crash automatically)?


  • in case data was wrong or corrupted, can the user see this easily (maybe after a restart of the program)? If yes, you may offer an option to let the user save the data, then force a restart, reload it and let the user check if the data looks fine.



If that this "intermediate backup" strategy is a sensible option depends ultimately on the application and its architecture, and on the nature and structure of the data involved. But if the user will loose less than 10 minutes of work, and such a crash happens once a week or even more seldom, I would probably not invest too much thought into this.






share|improve this answer




































    0


















    Considering that this is meant for a chemical lab and that your application does not control the instruments directly but rather through other services:



    Force termination after showing the message. After an unhandled exception your application is in an unknown state. It could send erroneous commands. It can even invoke nasal demons. An erroneous command could potentially waste expensive reagents or bring danger to equipment or people.



    But you can do something else: gracefully recover after restarting. I assume that your application doesn't bring down those background services with itself when it crashes. In that case you can easily recover the state from them. Or, if you have more state, consider saving it. In a storage which has provisions for data atomicity and integrity (SQLite maybe?).






    share|improve this answer




























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "131"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });















      draft saved

      draft discarded
















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f399424%2fhow-to-treat-unhandled-exceptions-terminate-the-application-vs-keep-it-alive%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown


























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      5


















      It depends to some extent on the application you're developing but in general, I'd say that if your application encounters an unhandled exception, you need to terminate it.



      Why?



      Because you can no longer have any confidence in the state of the application.



      Definitely, provide a helpful message to the user, but you should ultimately terminate the application.



      Edit having looked at the context, I would definitely want the application to terminate. You do not want software running in a lab to produce corrupt output and since you didn't think to handle the exception, you have no idea why it was thrown and what is happening.






      share|improve this answer





























      • I tried to add some context information about the application in the last part.

        – Jonas Benz
        8 hours ago











      • Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?

        – Jonas Benz
        8 hours ago











      • @JonasBenz Isn't it better for the user if he is able to save before he restarts the application? Yes, but how do you know if the data the user would be saving is valid and not corrupt? At this point, you've got an unexpected exception and you really don't know why. Your safest path, albeit annoying to the user, is to terminate the application. If you're concerned about the user saving work, you would employ a constant-saving strategy. Again, it all depends on the application you're writing.

        – Matthew
        7 hours ago













      • I agree that terminating is the safest solution. Therefore I would also suggest it in the error message (and do it, if the user not explicitly wants to keep it alive). But why not let the user decide? You don't know what does the bigger harm. A constant-saving strategy is not an option because the user has to enter a "reason for change" on every save. It is not only about saving... Maybe he want to stop an instrument in an error case.

        – Jonas Benz
        7 hours ago











      • The .NET framework seems to do something similar and asks the user in some cases: “Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.” Can't you argue the same way here? Why is there a "Continue" button?

        – Jonas Benz
        7 hours ago
















      5


















      It depends to some extent on the application you're developing but in general, I'd say that if your application encounters an unhandled exception, you need to terminate it.



      Why?



      Because you can no longer have any confidence in the state of the application.



      Definitely, provide a helpful message to the user, but you should ultimately terminate the application.



      Edit having looked at the context, I would definitely want the application to terminate. You do not want software running in a lab to produce corrupt output and since you didn't think to handle the exception, you have no idea why it was thrown and what is happening.






      share|improve this answer





























      • I tried to add some context information about the application in the last part.

        – Jonas Benz
        8 hours ago











      • Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?

        – Jonas Benz
        8 hours ago











      • @JonasBenz Isn't it better for the user if he is able to save before he restarts the application? Yes, but how do you know if the data the user would be saving is valid and not corrupt? At this point, you've got an unexpected exception and you really don't know why. Your safest path, albeit annoying to the user, is to terminate the application. If you're concerned about the user saving work, you would employ a constant-saving strategy. Again, it all depends on the application you're writing.

        – Matthew
        7 hours ago













      • I agree that terminating is the safest solution. Therefore I would also suggest it in the error message (and do it, if the user not explicitly wants to keep it alive). But why not let the user decide? You don't know what does the bigger harm. A constant-saving strategy is not an option because the user has to enter a "reason for change" on every save. It is not only about saving... Maybe he want to stop an instrument in an error case.

        – Jonas Benz
        7 hours ago











      • The .NET framework seems to do something similar and asks the user in some cases: “Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.” Can't you argue the same way here? Why is there a "Continue" button?

        – Jonas Benz
        7 hours ago














      5














      5










      5









      It depends to some extent on the application you're developing but in general, I'd say that if your application encounters an unhandled exception, you need to terminate it.



      Why?



      Because you can no longer have any confidence in the state of the application.



      Definitely, provide a helpful message to the user, but you should ultimately terminate the application.



      Edit having looked at the context, I would definitely want the application to terminate. You do not want software running in a lab to produce corrupt output and since you didn't think to handle the exception, you have no idea why it was thrown and what is happening.






      share|improve this answer
















      It depends to some extent on the application you're developing but in general, I'd say that if your application encounters an unhandled exception, you need to terminate it.



      Why?



      Because you can no longer have any confidence in the state of the application.



      Definitely, provide a helpful message to the user, but you should ultimately terminate the application.



      Edit having looked at the context, I would definitely want the application to terminate. You do not want software running in a lab to produce corrupt output and since you didn't think to handle the exception, you have no idea why it was thrown and what is happening.







      share|improve this answer















      share|improve this answer




      share|improve this answer



      share|improve this answer








      edited 7 hours ago

























      answered 8 hours ago









      MatthewMatthew

      6271 silver badge7 bronze badges




      6271 silver badge7 bronze badges
















      • I tried to add some context information about the application in the last part.

        – Jonas Benz
        8 hours ago











      • Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?

        – Jonas Benz
        8 hours ago











      • @JonasBenz Isn't it better for the user if he is able to save before he restarts the application? Yes, but how do you know if the data the user would be saving is valid and not corrupt? At this point, you've got an unexpected exception and you really don't know why. Your safest path, albeit annoying to the user, is to terminate the application. If you're concerned about the user saving work, you would employ a constant-saving strategy. Again, it all depends on the application you're writing.

        – Matthew
        7 hours ago













      • I agree that terminating is the safest solution. Therefore I would also suggest it in the error message (and do it, if the user not explicitly wants to keep it alive). But why not let the user decide? You don't know what does the bigger harm. A constant-saving strategy is not an option because the user has to enter a "reason for change" on every save. It is not only about saving... Maybe he want to stop an instrument in an error case.

        – Jonas Benz
        7 hours ago











      • The .NET framework seems to do something similar and asks the user in some cases: “Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.” Can't you argue the same way here? Why is there a "Continue" button?

        – Jonas Benz
        7 hours ago



















      • I tried to add some context information about the application in the last part.

        – Jonas Benz
        8 hours ago











      • Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?

        – Jonas Benz
        8 hours ago











      • @JonasBenz Isn't it better for the user if he is able to save before he restarts the application? Yes, but how do you know if the data the user would be saving is valid and not corrupt? At this point, you've got an unexpected exception and you really don't know why. Your safest path, albeit annoying to the user, is to terminate the application. If you're concerned about the user saving work, you would employ a constant-saving strategy. Again, it all depends on the application you're writing.

        – Matthew
        7 hours ago













      • I agree that terminating is the safest solution. Therefore I would also suggest it in the error message (and do it, if the user not explicitly wants to keep it alive). But why not let the user decide? You don't know what does the bigger harm. A constant-saving strategy is not an option because the user has to enter a "reason for change" on every save. It is not only about saving... Maybe he want to stop an instrument in an error case.

        – Jonas Benz
        7 hours ago











      • The .NET framework seems to do something similar and asks the user in some cases: “Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.” Can't you argue the same way here? Why is there a "Continue" button?

        – Jonas Benz
        7 hours ago

















      I tried to add some context information about the application in the last part.

      – Jonas Benz
      8 hours ago





      I tried to add some context information about the application in the last part.

      – Jonas Benz
      8 hours ago













      Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?

      – Jonas Benz
      8 hours ago





      Yes, of course the application could be in an invalid state. Maybe some ViewModel's only got updated partly. But can this do any harm? The user can reload the data and if something invalid will be send to the service, then the service will not accept it anyway. Isn't it better for the user if he is able to save before he restarts the application?

      – Jonas Benz
      8 hours ago













      @JonasBenz Isn't it better for the user if he is able to save before he restarts the application? Yes, but how do you know if the data the user would be saving is valid and not corrupt? At this point, you've got an unexpected exception and you really don't know why. Your safest path, albeit annoying to the user, is to terminate the application. If you're concerned about the user saving work, you would employ a constant-saving strategy. Again, it all depends on the application you're writing.

      – Matthew
      7 hours ago







      @JonasBenz Isn't it better for the user if he is able to save before he restarts the application? Yes, but how do you know if the data the user would be saving is valid and not corrupt? At this point, you've got an unexpected exception and you really don't know why. Your safest path, albeit annoying to the user, is to terminate the application. If you're concerned about the user saving work, you would employ a constant-saving strategy. Again, it all depends on the application you're writing.

      – Matthew
      7 hours ago















      I agree that terminating is the safest solution. Therefore I would also suggest it in the error message (and do it, if the user not explicitly wants to keep it alive). But why not let the user decide? You don't know what does the bigger harm. A constant-saving strategy is not an option because the user has to enter a "reason for change" on every save. It is not only about saving... Maybe he want to stop an instrument in an error case.

      – Jonas Benz
      7 hours ago





      I agree that terminating is the safest solution. Therefore I would also suggest it in the error message (and do it, if the user not explicitly wants to keep it alive). But why not let the user decide? You don't know what does the bigger harm. A constant-saving strategy is not an option because the user has to enter a "reason for change" on every save. It is not only about saving... Maybe he want to stop an instrument in an error case.

      – Jonas Benz
      7 hours ago













      The .NET framework seems to do something similar and asks the user in some cases: “Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.” Can't you argue the same way here? Why is there a "Continue" button?

      – Jonas Benz
      7 hours ago





      The .NET framework seems to do something similar and asks the user in some cases: “Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.” Can't you argue the same way here? Why is there a "Continue" button?

      – Jonas Benz
      7 hours ago













      5


















      You have to expect your program to terminate for more reasons than just an unhandled exception anyway, like a power failure, or a different background process which crashes the whole system. Therefore I would recommend to terminate and restart the application, but with some measures to mitigate the consequences of such a restart and minimize the possible data loss.



      Start with analysing the following points:




      • how much data can actually get lost in case of a program termination?


      • how severe is such a loss really for the user? Can the lost data reconstructed in less than 5 minutes, or are we talking about losing a days work?


      • how much effort it is for you to implement some "intermediate backup" strategy (which saves not to the data pool where, as you wrote, the user would have to enter a change reason, but to something like a temporary file, which may be reloaded after a program crash automatically)?


      • in case data was wrong or corrupted, can the user see this easily (maybe after a restart of the program)? If yes, you may offer an option to let the user save the data, then force a restart, reload it and let the user check if the data looks fine.



      If that this "intermediate backup" strategy is a sensible option depends ultimately on the application and its architecture, and on the nature and structure of the data involved. But if the user will loose less than 10 minutes of work, and such a crash happens once a week or even more seldom, I would probably not invest too much thought into this.






      share|improve this answer

































        5


















        You have to expect your program to terminate for more reasons than just an unhandled exception anyway, like a power failure, or a different background process which crashes the whole system. Therefore I would recommend to terminate and restart the application, but with some measures to mitigate the consequences of such a restart and minimize the possible data loss.



        Start with analysing the following points:




        • how much data can actually get lost in case of a program termination?


        • how severe is such a loss really for the user? Can the lost data reconstructed in less than 5 minutes, or are we talking about losing a days work?


        • how much effort it is for you to implement some "intermediate backup" strategy (which saves not to the data pool where, as you wrote, the user would have to enter a change reason, but to something like a temporary file, which may be reloaded after a program crash automatically)?


        • in case data was wrong or corrupted, can the user see this easily (maybe after a restart of the program)? If yes, you may offer an option to let the user save the data, then force a restart, reload it and let the user check if the data looks fine.



        If that this "intermediate backup" strategy is a sensible option depends ultimately on the application and its architecture, and on the nature and structure of the data involved. But if the user will loose less than 10 minutes of work, and such a crash happens once a week or even more seldom, I would probably not invest too much thought into this.






        share|improve this answer































          5














          5










          5









          You have to expect your program to terminate for more reasons than just an unhandled exception anyway, like a power failure, or a different background process which crashes the whole system. Therefore I would recommend to terminate and restart the application, but with some measures to mitigate the consequences of such a restart and minimize the possible data loss.



          Start with analysing the following points:




          • how much data can actually get lost in case of a program termination?


          • how severe is such a loss really for the user? Can the lost data reconstructed in less than 5 minutes, or are we talking about losing a days work?


          • how much effort it is for you to implement some "intermediate backup" strategy (which saves not to the data pool where, as you wrote, the user would have to enter a change reason, but to something like a temporary file, which may be reloaded after a program crash automatically)?


          • in case data was wrong or corrupted, can the user see this easily (maybe after a restart of the program)? If yes, you may offer an option to let the user save the data, then force a restart, reload it and let the user check if the data looks fine.



          If that this "intermediate backup" strategy is a sensible option depends ultimately on the application and its architecture, and on the nature and structure of the data involved. But if the user will loose less than 10 minutes of work, and such a crash happens once a week or even more seldom, I would probably not invest too much thought into this.






          share|improve this answer
















          You have to expect your program to terminate for more reasons than just an unhandled exception anyway, like a power failure, or a different background process which crashes the whole system. Therefore I would recommend to terminate and restart the application, but with some measures to mitigate the consequences of such a restart and minimize the possible data loss.



          Start with analysing the following points:




          • how much data can actually get lost in case of a program termination?


          • how severe is such a loss really for the user? Can the lost data reconstructed in less than 5 minutes, or are we talking about losing a days work?


          • how much effort it is for you to implement some "intermediate backup" strategy (which saves not to the data pool where, as you wrote, the user would have to enter a change reason, but to something like a temporary file, which may be reloaded after a program crash automatically)?


          • in case data was wrong or corrupted, can the user see this easily (maybe after a restart of the program)? If yes, you may offer an option to let the user save the data, then force a restart, reload it and let the user check if the data looks fine.



          If that this "intermediate backup" strategy is a sensible option depends ultimately on the application and its architecture, and on the nature and structure of the data involved. But if the user will loose less than 10 minutes of work, and such a crash happens once a week or even more seldom, I would probably not invest too much thought into this.







          share|improve this answer















          share|improve this answer




          share|improve this answer



          share|improve this answer








          edited 5 hours ago

























          answered 5 hours ago









          Doc BrownDoc Brown

          144k25 gold badges269 silver badges426 bronze badges




          144k25 gold badges269 silver badges426 bronze badges


























              0


















              Considering that this is meant for a chemical lab and that your application does not control the instruments directly but rather through other services:



              Force termination after showing the message. After an unhandled exception your application is in an unknown state. It could send erroneous commands. It can even invoke nasal demons. An erroneous command could potentially waste expensive reagents or bring danger to equipment or people.



              But you can do something else: gracefully recover after restarting. I assume that your application doesn't bring down those background services with itself when it crashes. In that case you can easily recover the state from them. Or, if you have more state, consider saving it. In a storage which has provisions for data atomicity and integrity (SQLite maybe?).






              share|improve this answer































                0


















                Considering that this is meant for a chemical lab and that your application does not control the instruments directly but rather through other services:



                Force termination after showing the message. After an unhandled exception your application is in an unknown state. It could send erroneous commands. It can even invoke nasal demons. An erroneous command could potentially waste expensive reagents or bring danger to equipment or people.



                But you can do something else: gracefully recover after restarting. I assume that your application doesn't bring down those background services with itself when it crashes. In that case you can easily recover the state from them. Or, if you have more state, consider saving it. In a storage which has provisions for data atomicity and integrity (SQLite maybe?).






                share|improve this answer





























                  0














                  0










                  0









                  Considering that this is meant for a chemical lab and that your application does not control the instruments directly but rather through other services:



                  Force termination after showing the message. After an unhandled exception your application is in an unknown state. It could send erroneous commands. It can even invoke nasal demons. An erroneous command could potentially waste expensive reagents or bring danger to equipment or people.



                  But you can do something else: gracefully recover after restarting. I assume that your application doesn't bring down those background services with itself when it crashes. In that case you can easily recover the state from them. Or, if you have more state, consider saving it. In a storage which has provisions for data atomicity and integrity (SQLite maybe?).






                  share|improve this answer














                  Considering that this is meant for a chemical lab and that your application does not control the instruments directly but rather through other services:



                  Force termination after showing the message. After an unhandled exception your application is in an unknown state. It could send erroneous commands. It can even invoke nasal demons. An erroneous command could potentially waste expensive reagents or bring danger to equipment or people.



                  But you can do something else: gracefully recover after restarting. I assume that your application doesn't bring down those background services with itself when it crashes. In that case you can easily recover the state from them. Or, if you have more state, consider saving it. In a storage which has provisions for data atomicity and integrity (SQLite maybe?).







                  share|improve this answer













                  share|improve this answer




                  share|improve this answer



                  share|improve this answer










                  answered 4 hours ago









                  Jan DorniakJan Dorniak

                  2661 silver badge5 bronze badges




                  2661 silver badge5 bronze badges


































                      draft saved

                      draft discarded



















































                      Thanks for contributing an answer to Software Engineering Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f399424%2fhow-to-treat-unhandled-exceptions-terminate-the-application-vs-keep-it-alive%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown









                      Popular posts from this blog

                      Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

                      The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

                      Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...