Skip to main content
Tweeted twitter.com/StackSoftEng/status/822754985737850880

There are cases where I don't know how to use exception handling. To make it clear, let me divide exceptions into two types:

1- exceptional cases that may happen occasionally, such as when you try to open a non-existent file. 2- exceptions that you wouldn't except to happen, if you have written your program correctly, such as out-of-range indexing.

  1. exceptional cases that may happen occasionally, such as when you try to open a non-existent file.

  2. exceptions that you wouldn't expect to happen if you have written your program correctly, such as out-of-range indexing.

In the first case i'dI'd prompt the user and/or return the program to a normal state, but I don't know what to do for the second type. If I don't catch them, the runtime will show its own message. If I wanted to handle it myself, I would have no idea of how to handle a case that was not supposed to happen whatsoever.

There are cases where I don't know how to use exception handling. To make it clear, let me divide exceptions into two types:

1- exceptional cases that may happen occasionally, such as when you try to open a non-existent file. 2- exceptions that you wouldn't except to happen, if you have written your program correctly, such as out-of-range indexing.

In the first case i'd prompt the user and/or return the program to a normal state, but I don't know what to do for the second type. If I don't catch them, the runtime will show its own message. If I wanted to handle it myself, I would have no idea of how to handle a case that was not supposed to happen whatsoever.

There are cases where I don't know how to use exception handling. To make it clear, let me divide exceptions into two types:

  1. exceptional cases that may happen occasionally, such as when you try to open a non-existent file.

  2. exceptions that you wouldn't expect to happen if you have written your program correctly, such as out-of-range indexing.

In the first case I'd prompt the user and/or return the program to a normal state, but I don't know what to do for the second type. If I don't catch them, the runtime will show its own message. If I wanted to handle it myself, I would have no idea of how to handle a case that was not supposed to happen whatsoever.

Source Link

What to do with exceptions that arise from bugs?

There are cases where I don't know how to use exception handling. To make it clear, let me divide exceptions into two types:

1- exceptional cases that may happen occasionally, such as when you try to open a non-existent file. 2- exceptions that you wouldn't except to happen, if you have written your program correctly, such as out-of-range indexing.

In the first case i'd prompt the user and/or return the program to a normal state, but I don't know what to do for the second type. If I don't catch them, the runtime will show its own message. If I wanted to handle it myself, I would have no idea of how to handle a case that was not supposed to happen whatsoever.