Ә ұқ
ғ ү қң қ қ. өң құғ қ ғ ү қ қ, қ қғ ғ қ ұ - қ . қ ғ ө:
қ. қ ә ң қ , ң қ, ңң ө ә .. .
қ қ, ң ұ құ .
қ қ ұ- ң ң әң ұ ә қ қ ә қ қ.
ғ . C++ Builder ғ ғң ғ қ ә ұ ү қ TObject - TException , ұ ң SysUtils .
Қ. TException ғ ғ ү қғ қ:
Message қ ( AnsiString) ғң қң ұ ғ ү қ.
__property AnsiString Message = {read=FMessage, write=FMessage};
HelpContext қ ( THelpContext) қ ү ү қғ қ ә өң ө ү қ.
__property int HelpContext = {read
=FHelpContext, write=FHelpContext, nodefault};
ғ өң. Қ ғ өң ү ү : ғ өң / / ә өң / /. Қғ ғ өңң ұ қ Application ң қ , Application ү ғң ғ ө TExceptionEvent OnException қғ , ғ қғң өң, қғ ғ өңң қ қ. Ә қғ ғ өң ұ- Application ң ә HandleException(System::TObject* Sender); . ұ қ қ қң ShowException(System::TObject* ExceptObject, void * ExceptAddr); ә, ғ ғң ғ, ұ ғ, қң ө өң ө ң ғ ғ өң ұ ө қғ /4.13- /.
|
|
4.13-. ғ
өң қң
өң қң :
try... catch ғ өң;
try... __finally .
try... atch . ғ өң ң өң қ ү try... atch .
:
Try
{ // қғғ ң
throw 1-ө;
/ / ұ ғ өң қ.
throw 2-ө;
...
throw n-ө;
} // қғғ ң ң
catch (1-өң ә ң )
{
1-ө ә өңң
}
catch (2-өң ә ң )
{
2-ө ә өңң
}
catch (n-өң ә ң )
{
n-ө ә өңң
}
ұғ, try ( ө, қ ө - ғ ) ө , {} қғ ғ әң қғғ қ , ғ ғ ғ ү қғғ .
Өң catch қ ө . қң ө, қң ө ү /... / ұ - өң , :
catch (int i)
{ // int өң
}
catch (char * str)
{ // char* өң
}
catch (...)
{ //- өң
}
ғ ұ
1-ғ. қ қ қ өң ө.
#include
#include
#include
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main()
{
double d = 1.0;
for (int i=0; i<4; i++)
{
Try
{
|
|
cout << endl<< "try-block bastaldi..." <<endl;
switch (i)
{
case 0:
throw " goldi laktiru "; // char* қ
case 1:
throw 5; // int.-ү қ.
default:
throw d; // double қ.
}
//
cout<< "Byl try-block-ka bailanisti orindalmaidi" << endl;
} // try-ң ң
catch (int i)
{ // int өң
cout << " Int laktirildi /thrown /: " << 1 << endl;
}
catch (char* str)
{ //char* өң
cout << "string-gol laktirildi: " << str << endl;
}
catch (...) { //- өң
cout << "kalgan type laktirildi."<< "Program will.terminate." << endl;
cin.ignore ();
return -1; // ғ
}
cout<< "sikldin soni"<< endl;
} // ң ң.
cout << "progr soni" << endl; // ұ
, ү catch (...) // қ
return 0;
}
ұ ө . - ң ә ә int, char* ә double қ қғғ қ. =0 ғ throw char* қ, char* ұғ өң ұ , ғ ә ғ, қ ң ғ, қ =1 ғ қғғ ғ throw int қ, ұғ catch(int i) өң. =2 ғ double , ғ ә catch қғ, қ - ғ ү ү catch (...) ұ ә ғ ғ cin.ignore () ә return -1; ғ қ , ғ ө =3 ү ү.
ң ә:
2-ғ. Windows-ғ ғ қ қ -
өңң / / ө ө;
өң ө ө.
өңң ұ ө ү өң қ қ ұ , ү Tools -> Debugger Options , ғ Language Exceptions ң Stop on Delphi Exceptions ә Stop On C++ Exceptions Integrated debugging ғ /4.14(,,)-4.15(,,) /.
ә:
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
float a,b,c;
float d,x1,x2;
a=StrToInt(Edit1->Text);
b=StrToInt(Edit2->Text);
c=StrToInt(Edit3->Text);
Try
{ d=b/a;
x1=log(c);
x2= d;
Edit4->Text=FloatToStrF(x1,ffGeneral,5,2);
Edit5->Text=FloatToStrF(x2,ffGeneral,5,2);
}
catch(...)
{ MessageDlg("try- ",mtError, TMsgDlgButtons()
<< mbOK, 0);
//return;
}
Edit6->Text=" ";
ң :
1) өң / / ұ.
4.14-. ) ғ өң
|
|
/ / ұ.
4.14-. ) ғ өң
/ / ұ.
4.14-. ) ғ өң
/ / ұ.
2) өң / / ұ.
4.15-. ) ғ өң /
/ ұ ә қң өң.
4.15-. ) ғ өң /
/ ұ ә қң өң.
4.15-. ) ғ өң /
/ ұ ә қң өң.
try__ finally ң ( қғғ ң) ғ :
Try
{
//қғғ
}
__ finally
{
// ғ
}
Ө ұ
ұғ ғ ғ қ өң / ә өң/ қң.
ң ө .
Ү қғ үұң .
ң ө .
ҳң ( қғ).
ң .
ҳң ( қғ).
қғ ә ғ ұ үұң .
ү қ .
қ ә ү .
ө .
</endl;
9 - қ ұ.