⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_exception.c

📁 c语言是面向过程的程序语言
💻 C
字号:
/* ****************************** * Object Oriented Programming in C * * Author: Laurent Deniau, Laurent.Deniau@cern.ch * * For more information, please see the paper: * http://home.cern.ch/ldeniau/html/oopc/oopc.html * ****************************** */#include <stdio.h>#include <math.h>#include <exception.h>/* can also be #defined */enum { no_exception, zero_divide, domain_error } exceptions;doublediv_(double a, double b){  if (b == 0.0) throw(zero_divide);  return a/b;}doubleln_(double a){  if (a <= 0.0) throw(domain_error);  return log(a);}intmain(int argc, char *argv[]){  double a, b;  if (argc!=3) return EXIT_FAILURE;  a = atof(argv[1]);  b = atof(argv[2]);  try {    printf("ln(%g/%g) = %g\n", a, b, ln_(div_(a,b)));  }  catch(zero_divide) {    printf("zero division\n");  }  catch(domain_error) {    printf("domain error\n");  }  catch_any {    printf("unknow exception no %d\n", exception);  }  endtry;  return EXIT_SUCCESS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -