powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / C++ [игнор отключен] [закрыт для гостей] / TRY CATCH
4 сообщений из 4, страница 1 из 1
TRY CATCH
    #34708863
surpriserus
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Всем привет. Пытаюсь разобраться с исключениями в builder C++.
написал простенький тест:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
double d = sqrt(-4);
Edit1->Text = FloatToStr(d);
}
catch(...)
{
Application->MessageBoxA("Error","Error",MB_OK);
}

}
ошибка вылетает Билдеровская все время а моя нет, я в настройках (Tools\Debugger Options) отключил все что только можно было. не помогло. Пробовал просто скомпиленный EXE файл запустить все равно такая же хрень.
Может кто знает что делать ?
...
Рейтинг: 0 / 0
TRY CATCH
    #34708876
Tubrik
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
может это не есть исключение
...
Рейтинг: 0 / 0
TRY CATCH
    #34708886
Tubrik
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
	try
	{
		int a, b;
		scanf("%d", &a);
		scanf("%d", &b);
		int d = a / b;
		printf("\n%d\n", d);
	}
	catch(...)
	{
		printf("\nexc\n");
	}

так работает
...
Рейтинг: 0 / 0
TRY CATCH
    #34709105
Тынц.
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
sqrt - неудачная функция для примера ловли исключений...
Дело в том, что Борландовская реализация библиотеки math в случае ошибок выплёвывает месажбокс с информацией об ошибке, если не задан обработчик _matherr/_matherrl.
Borland C++ Builder Help
............
Prototype

double sqrt(double x);

long double sqrtl(long double x);
..................
Error handling for these functions can be modified through the functions _matherr and _matherrl.


ну и
Borland C++ Builder Help
Header File

math.h

Category

Diagnostic Routines, Math Routines

Prototype

int _matherr(struct _exception *e);

int _matherrl(struct _exceptionl *e);

Description

User-modifiable math error handler.

_matherr is called when an error is generated by the math library.

_matherrl is the long double version; it is called when an error is generated by the long double math functions.

_matherr and _matherrl each serve as a user hook (a function that can be customized by the user) that you can replace by writing your own math error-handling routine.

_matherr and _matherrl are useful for information on trapping domain and range errors caused by the math functions. They do not trap floating-point exceptions, such as division by zero. See signal for information on trapping such errors.

You can define your own _matherr or _matherrl routine to be a custom error handler (such as one that catches and resolves certain types of errors); this customized function overrides the default version in the C library. The customized _matherr or _matherrl should return 0 if it fails to resolve the error, or nonzero if the error is resolved. When _matherr or _matherrl return nonzero, no error message is printed and the global variable errno is not changed.
......................

Ну и поскольку "They do not trap floating-point exceptions, such as division by zero.", пример с делением на 0 работает.
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / C++ [игнор отключен] [закрыт для гостей] / TRY CATCH
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]