🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #797

Re: Obsluga wyjatkow?

#797
From: Marek Barbaszynski
Date: Mon, 26 Jan 1998 15:03
71 lines
2172 bytes
Mikolaj Rydzewski <mrydzews@infoserv.ii.uj.edu.pl> wrote:
> : Czesc!
> 
> : Mam pewien problem zwiazany z obsluga wyjatkow w C++. Chcialem sobie
> : przechwycic wyjatek dzielenia przez zero i nic z tego nie wyniklo - tzn.
> : wyniklo, ale przerwanie programu, a nie przechwycenie wyjatku. Jeszcze
> : gorzej bylo z odwolaniem sie do pustego wskaznika. Testowalem to na c++ pod
> : Linuxem i SunOS'em oraz na Visual C++ 4.0
> 
> : try
> : {   int x, y=0;
> :     x=x/y;
> : }
> : catch(...)
> : {   cout << "catch!" << endl;
> : }
[Ciach!]

Dla Visual C++ polecam zastosowanie funkcji _set_se_translator, ktora
pozwala na zadanie wlasnego tlumaczenia wyjatkow systemowych na wyjatki
C++. Oto maly przyklad:

/*  SETRANS.CPP 
 */

#include <stdio.h>
#include <windows.h>
#include <eh.h>

void SEFunc();
void trans_func( unsigned int, EXCEPTION_POINTERS* );

class SE_Exception
{
private:
    unsigned int nSE;
public:
    SE_Exception() {}
    SE_Exception( unsigned int n ) : nSE( n ) {}
    ~SE_Exception() {}
    unsigned int getSeNumber() { return nSE; }
};
void main( void )
{
    try
    {
        _set_se_translator( trans_func );
        SEFunc();
    }
    catch( SE_Exception e )
    {
        printf( "Caught a __try exception with SE_Exception.\n" );
    }
}
void SEFunc()
{
    __try
    {
        int x, y=0;
        x = 5 / y;
    }
    __finally
    {
        printf( "In finally\n" );
    }
}
void trans_func( unsigned int u, EXCEPTION_POINTERS* pExp )
{
    printf( "In trans_func.\n" );
    throw SE_Exception();
}
Technical Details
Message-ID: <34CCA5C8.2773@nospam.impaq.com.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!news.icm.edu.pl!not-for-mail
References: <6a1vod$noc$1@info.cyf-kr.edu.pl> <6ai3lt$npt@polonez.man.lodz.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!news.icm.edu.pl!not-for-mail
From: Marek Barbaszynski <mb@nospam.impaq.com.pl>
Newsgroups: pl.comp.lang.c
Subject: Re: Obsluga wyjatkow?
Date: Mon, 26 Jan 1998 16:03:36 +0100
Organization: ICM's news server
Lines: 71
Message-ID: <34CCA5C8.2773@nospam.impaq.com.pl>
References: <6a1vod$noc$1@info.cyf-kr.edu.pl> <6ai3lt$npt@polonez.man.lodz.pl>
NNTP-Posting-Host: smaug.piap.waw.pl
Mime-Version: 1.0
X-Mailer: Mozilla 3.0 (WinNT; I)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit