Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
EXTERNAL_HEADERS
RSL
examples
tutorial
stdexcept.cpp
Go to the documentation of this file.
1
29
#include <string>
// for string
30
#include <stdexcept>
// for exception, runtime_error, out_of_range
31
#include <iostream>
// for cout
32
33
#include <
examples.h
>
34
35
36
#ifndef _RWSTD_NO_EXCEPTIONS
37
38
int
main
() {
39
40
// First we'll incite and catch an exception from the C++ Standard
41
// library class std::string by attempting to replace a substring
42
// starting at a position beyond the end of the string object.
43
try
{
44
std::string ().replace (100, 1, 1,
'c'
);
45
}
46
catch
(std::out_of_range &
e
) {
47
48
// Print out the exception string, which in this implementation
49
// includes the location and the name of the function that threw
50
// the exception along with the reason for the exception.
51
std::cout <<
"Caught an out_of_range exception: "
52
<<
e
.what () <<
'\n'
;
53
}
54
catch
(
std::exception
&
e
) {
55
56
std::cout <<
"Caught an exception of an unexpected type: "
57
<<
e
.what () <<
'\n'
;
58
}
59
catch
(...) {
60
std::cout <<
"Caught an unknown exception\n"
;
61
}
62
63
// Throw another exception.
64
try
{
65
throw
std::runtime_error (
"a runtime error"
);
66
}
67
catch
(std::runtime_error &
e
) {
68
std::cout <<
"Caught a runtime_error exception: "
69
<<
e
.what () <<
'\n'
;
70
}
71
catch
(
std::exception
&
e
) {
72
std::cout <<
"Caught an exception of an unexpected type: "
73
<<
e
.what () <<
'\n'
;
74
}
75
catch
(...) {
76
std::cout <<
"Caught an unknown exception\n"
;
77
}
78
79
return
0;
80
}
81
82
#else
// if defined (_RWSTD_NO_EXCEPTIONS)
83
84
int
main
() {
85
86
std::cout <<
"Exception support disabled.\n"
;
87
88
return
0;
89
}
90
91
#endif
// _RWSTD_NO_EXCEPTIONS
e
#define e
Definition
17.names.cpp:118
std::exception
Definition
STD_EXCEPTION.cpp:37
examples.h
main
int main()
Definition
stdexcept.cpp:38
Generated by
1.9.8