[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

Chapter 4.

 

19 Diagnostics Library



This chapter describes objects and facilities used to report error conditions.


Overview of Diagnostics library

This chapter contains objects for error testing and reporting.

"19.1 Exception Classes"

"19.2 Assertions"

"19.3 Error Numbers"


19.1 Exception Classes

The library provides for exception classes for use with logic errors and runtime errors. Logic errors in theory can be predicted in advance while runtime errors can not. The header <stdexcept> predefines several types of exceptions for C++ error reporting.

Header <stdexcept>:


namespace std {
class logic_error;
class domain_error;
class invalid_argument;
class length_error;
class out_of_range;
class runtime_error;
class range_error;
class overflow_error;
class underflow_error;
}


19.1.1 Class Logic_error

The logic_error class is derived from the "18.6.1 Class Exception," and is used for exceptions that are detectable before program execution.

Class logic_error:


namespace std {
class logic_error : public exception {
public:
explicit logic_error(const string& what_arg);
};
}

Constructors

Constructs an object of class logic_error. Initializes exception::what to the what_arg argument.

Prototype:

logic_error(const string& what_arg);

19.1.2 Class domain_error

A derived class of logic error the domain_error object is used for exceptions of domain errors.

Class domain_error:


namespace std {
class domain_error : public logic_error {
public:
explicit domain_error(const string& what_arg);
};
}


Constructors

Constructs an object of domain_error. Initializes exception::what to the what_arg argument

Prototype:

domain_error(const string& what_arg);

19.1.3 Class Invalid_argument

A derived class of logic_error the invalid_argument is used for exceptions of invalid arguments.

Class invalid_argument:


namespace std {
class invalid_argument : public logic_error {
public:
explicit invalid_argument(const string& what_arg);
};
}


Constructors

Constructs an object of class invalid_argument. Initializes exception::what to the what_arg argument

Prototype:

invalid_argument(const string& what_arg);

19.1.4 Class Length_error

A derived class of logic_error the length_error is use to report exceptions when an object exceeds allowed sizes.

Class length_error:


namespace std {
class length_error : public logic_error {
public:
explicit length_error(const string& what_arg);
};
}


Constructors

Constructs an object of class length_error. Initializes exception::what to the what_arg argument

Prototype:

length_error(const string& what_arg);

19.1.5 Class Out_of_range

A derived class of logic_error an object of out_of_range is used for exceptions for out of range errors.

Class out_of_range:


namespace std {
class out_of_range : public logic_error {
public:
explicit out_of_range(const string& what_arg);
};
}


Constructors

Constructs an object of the class out_of_range. Initializes exception::what to the what_arg argument

Prototype:

out_of_range(const string& what_arg);

19.1.6 Class Runtime_error

Derived from the "18.6.1 Class Exception," the runtime_error object is used to report errors detectable only during runtime.

Class runtime_error:


namespace std {
class runtime_error : public exception {
public:
explicit runtime_error(const string& what_arg);
};
}


Constructors

Constructs an object of the class runtime_error. Initializes exception::what to the what_arg argument

Prototype:

runtime_error(const string& what_arg);

19.1.7 Class Range_error

Derived form the runtime_error class, an object of range_error is used for exceptions due to runtime out of range errors.

Class range_error:


namespace std {
class range_error : public runtime_error {
public:
explicit range_error(const string& what_arg);
};
}


Constructors

Constructs an object of the class range_error. Initializes exception::what to the what_arg argument

Prototype:

range_error(const string& what_arg);

19.1.8 Class Overflow_error

The overflow_error object is derived from the class runtime_error and is used to report arithmetical overflow errors.

Class overflow_error:


namespace std {
class overflow_error : public runtime_error {
public:
explicit overflow_error(const string& what_arg);
};
}


Constructors

Constructs an object of the class overflow_error. Initializes exception::what to the what_arg argument

Prototype:

overflow_error(const string& what_arg);

19.1.9 Class Underflow_error

The class underflow_error is derived from the class runtime_error and is used to report the arithmetical underflow error.

Class underflow_error:


namespace std {
class underflow_error : public runtime_error {
public:
explicit underflow_error(const string& what_arg);
};
}


Constructors

Constructs an object of the class underflow_error. Initializes exception::what to the what_arg argument

Prototype:

underflow_error(const string& what_arg);

19.2 Assertions

The header <cassert> provides for the assert macro and is used the same as the standard C header assert.h


19.3 Error Numbers

The header <cerrno> provides macros: EDOM ERANGE and errno to be used for domain and range errors reported by using the errno facility. The <cerrno> header is used the same as standard C header errno.h

 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: July 21, 2000