Programable exception handling.

M

Muzammil

Hi,
i m unable to make a programable exception handling.
i can just throw an exception and catch it and try for ones.
but its not enough, i want to an exception which can work untill user
dont put valid statements or condition.
and i want to learn more about it.
 
O

Obnoxious User

i want the exception handling like we do in visual c#. in which we dont
exit(terminate on catching in c++) from program.

Why do you think you need to exit when you catch an exception?
 
M

Muzammil

What exactly do you mean by this?


Well, that's how exceptions work, don't they?


You aren't really supposed to use exceptions for that. Wrong user input
is not an exceptional case.

i want the exception handling like we do in visual c#.
in which we dont exit(terminate on catching in c++) from program.
 
M

Muzammil

i want that if i found an error mean exception is thrown.
when we catch this exception then the next step is of try.
but this try action is taken one time not many times when error is
thrown. and program is terminated.
i dont want this.that my program going to terminate.

Christian said:
Muzammil said:
i want the exception handling like we do in visual c#.
in which we dont exit(terminate on catching in c++) from program.

Granted, I don't know much about C#, but from I gather from checking the
very first Google hit for "c# exception handling" [1], I don't see how
C# is any different with regard to uncaught exceptions:

| If a user (programmer) do not provide a mechanism to handle these
| anomalies, the .NET run time environment provide a default mechanism,
| which terminates the program execution.


So it is still not clear what you mean.

#include <stdexcept>
#include <iostream>

void f()
{
throw std::runtime_error("...");
}

void g()
{
try
{
f();
}
catch (std::runtime_error const &)
{
std::cout << "program does *not* terminate\n";
}

// ...
}


[1]
http://www.c-sharpcorner.com/Upload...282005051444AM/ExceptionHandlinginCSharp.aspx
 
F

Fred Zwarts

Muzammil said:
i want that if i found an error mean exception is thrown.
when we catch this exception then the next step is of try.
but this try action is taken one time not many times when error is
thrown. and program is terminated.

That is not true. Each time the exception is thrown at that place it will
be caught at the same try. Can you give an example of what you mean that
the try action is taken only once?
i dont want this.that my program going to terminate.

It only terminates if the exception is not caught.
If you do not catch an exception, the program has no choice but to terminate,
what else do you want to happen?
(Of course, you may override the global terminate() function,
but that has a lot of pitfalls and even then there is no way to continue the
program normally.)
Christian said:
Muzammil said:
i want the exception handling like we do in visual c#.
in which we dont exit(terminate on catching in c++) from program.

Granted, I don't know much about C#, but from I gather from checking the
very first Google hit for "c# exception handling" [1], I don't see how
C# is any different with regard to uncaught exceptions:

| If a user (programmer) do not provide a mechanism to handle these
| anomalies, the .NET run time environment provide a default mechanism,
| which terminates the program execution.


So it is still not clear what you mean.

#include <stdexcept>
#include <iostream>

void f()
{
throw std::runtime_error("...");
}

void g()
{
try
{
f();
}
catch (std::runtime_error const &)
{
std::cout << "program does *not* terminate\n";
}

// ...
}


[1]
http://www.c-sharpcorner.com/Upload...282005051444AM/ExceptionHandlinginCSharp.aspx
 
O

Obnoxious User

i want that if i found an error mean exception is thrown. when we
catch this exception then the next step is of try. but this try
action is taken one time not many times when error is thrown. and
program is terminated.
i dont want this.that my program going to terminate.

Why don't you post some code showing what you claim is not working?

#include <iostream>

int main() {
while(true) {
try {
throw "exception";
}
catch(char const * e) {
std::cout<<e<<std::endl;
}
}
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top