473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Throwing Exception

SK
What is the purpose of throwing exceptions in catch block.
Bcos the exception is already thrown only, it is coming to
the catch block.What is the purpose of throwing it again
then!!!.....Help
Jul 21 '05 #1
2 1494
SK <an*******@discussions.microsoft.com> wrote:
What is the purpose of throwing exceptions in catch block.
Bcos the exception is already thrown only, it is coming to
the catch block.What is the purpose of throwing it again
then!!!.....Help


You may want to log the exception, but then throw it so that higher
levels can deal with it more appropriately, for example.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
If for example you are writing an audio file conversion component, there may
be many different types of exception it would expect to encounter

1) File does not exist
2) Audio codec not installed
3) File is locked by another process

etc.
It wouldn't be reasonable to expect the user of your component to trap every
error that *you* expect to happen because these are exactly the types of
detail you are hiding from the user. So, you would trap the exception
yourself, maybe perform some kind of clean-up code, and then raise your own
CouldNotConvertFileException.

The user of your component then only needs to worry about that one exception
when trying to do

YourComponent.ConvertAudioFile();
For the sake of completeness, you can even throw your new exception and pass
the original exception as the "innerException", so the user can still see
exactly what caused the exception to start with.
--
Pete
====
Audio compression components, DIB graphics controls, FastStrings
http://www.droopyeyes.com

Read or write articles on just about anything
http://www.HowToDoThings.com
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Stephan | last post by:
why does the following code not work???? after compiling and running it will just say killed after all my memory filled up any suggestions? #include <iostream> using namespace std; void...
1
by: Farooq Khan | last post by:
i'm writing a class library having following code snippet. i want this class to report an error (by throwing an Exception) to the application using this class library. the problem is that within...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
9
by: Mark Rae | last post by:
Hi, Can anyone please tell me if there is any difference in throwing an exception with or without parentheses, e.g. try { /* code */
5
by: KJ | last post by:
This is kind of hard to explain but I have a The controls are created with CreateChildControls(). Now let say I click a button and an error occurs in the control. If I throw it up it goes back...
7
by: Sek | last post by:
Hi Folks! I was pondering over a code and noticed that exception handlers were present in the private, protected as well as public methods. And, ofcourse, public methods were calling priv/prot...
5
by: nospam_news | last post by:
When language changes make old code uncompilable, that's not what is called protection of investment. New compilers (g++ 3.2.3) reject classes where methods throw the class they belong to. gcc...
1
by: usenet | last post by:
I wrote some sample code (see below) for nested exception throwing i.e. my catch blocks are throwing exceptions of their own (for simplicity I used standard exceptions). I am getting some...
4
by: Jay Dee | last post by:
I have a query about throwing exceptions. To throw an exception I type something like: try { // do somthing } catch (ArgumentOutOfRangeException) {
21
by: Chris M. Thomasson | last post by:
Is it every appropriate to throw in a dtor? I am thinking about a simple example of a wrapper around a POSIX file... ________________________________________________________________________ class...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.