что можно поюзать вместо субжа?
всё бы ничего, но из блока try {} бывают return'ы и надо как-то обеспечить finally.
>что можно поюзать вместо субжа?
>всё бы ничего, но из блока try {} бывают return'ы и надо
>как-то обеспечить finally.Hi,
This is C++ not java, so
public:
void m1()
{
try {
// no returns and gotos from try block
if ( i_want_to_call_return ) {
finally();
return;
}
}
catch ( ... ) { // will catch any exception
}
finally();
}private:
void finally()
{
// your finally stuff
}Thanks
--- Sas:)
>>что можно поюзать вместо субжа?
>>всё бы ничего, но из блока try {} бывают return'ы и надо
>>как-то обеспечить finally.
>
>Hi,
>
>This is C++ not java, so
>
>public:
>void m1()
>{
> try {
> // no returns and gotos from try block
> if ( i_want_to_call_return ) {
> finally();
> return;
> }
> }
> catch ( ... ) { // will catch any exception
> }
> finally();
>}
>
>private:
>void finally()
>{
> // your finally stuff
>}
>
>Thanks
>--- Sas
>
>:)
Или как вариант:void xxx()
{
try
{
try
{
bla;
bla;
bla;
// вместо return генерируем искючение
excetp ...
}
catch
{
//обрабатываем ошибки внутри функции (все, кроме ...)
}
}
catch ...
{
// обрабатываем except ... = finally
}
}PS С основательно подзабыл, но думаю идея понятна.
Hi LS,Your solution is really better!
Thanks
--- Sas
Hi,LS's variant with try { try {} } is better.
Alos some corrections to code I have posted previously.
public:
void m1()
{
try {
// no returns and gotos from try block
if ( i_want_to_call_return ) {
finally();
return;
}
}
catch ( const some_exception& e ) {
finally(); // put finally if you need transparent exceptions
throw;
}
catch ( const some_other_exception& oe ) {
// no finally if we are not rethrow
}
catch ( ... ) { // will catch any exception
finally();
throw;
}
finally();
}
private:
void finally()
{
// your finally stuff
}
>что можно поюзать вместо субжа?
>всё бы ничего, но из блока try {} бывают return'ы и надо
>как-то обеспечить finally.A mozhet prosche ispol'zovat' destructory ob'ektov? Primerno tak:
class TEMP
{
public:
~TEMP()
{
//Do smth here
}
};
void function()
{
TEMP t;//bla-bla-bla
}Kogda function vozvraschaetsya, budet vyzvan destructor.