Bagikan melalui


Kelas logic_error

Kelas ini berfungsi sebagai kelas dasar untuk semua pengecualian yang dilemparkan untuk melaporkan kesalahan yang mungkin dapat dideteksi sebelum program dijalankan, seperti pelanggaran prasyarat logis.

Sintaks

class logic_error : public exception {
public:
    explicit logic_error(const string& message);

    explicit logic_error(const char *message);

};

Keterangan

Nilai yang dikembalikan oleh what() adalah salinan .message.data() Untuk informasi lebih lanjut, lihat what dan data.

Contoh

// logic_error.cpp
// compile with: /EHsc
#include <exception>
#include <iostream>
#include <stdexcept>
#include <typeinfo>
using namespace std;

int main()
{
   try
   {
      throw logic_error("Does not compute!");
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: Does not compute!
Type: class std::logic_error
*/

Persyaratan

Header:<stdexcept>

Namespace: std

Baca juga

Kelas pengecualian
Keamanan utas di Pustaka Standar C++