Dev - C++ - como manejar excepciones en una clase

 
Vista:

como manejar excepciones en una clase

Publicado por Liliana (2 intervenciones) el 18/11/2013 19:50:54
im trying to handling exception in my matriz class. I have no idea how this suppoosed to be

My matriz class its like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef Matriz_H
   #define Matriz_H
 
   #include <iostream>
   #include <iomanip>
 
   using namespace std;
 
   template <typename T> class Matriz ;
   template <typename T> std::istream& operator >> ( std::istream &is_in,Matriz <T> &M);
   template <typename T> std::ostream& operator << ( std::ostream &os_out, const Matriz <T> &M);
 
   template <typename T>
   class Matriz{
      friend ostream &operator << <> (ostream &, const Matriz <T> &);
      friend istream &operator >> <> (istream &, Matriz <T> &);
 
      public:
         Matriz (int = 5, int = 5);
         Matriz (const Matriz &);
         ~Matriz ();
 
         void setSize (int = 5, int = 5);
 
         const Matriz &operator = (const Matriz &);
         bool operator == (const Matriz &) const;
         Matriz operator * (const Matriz &);
         T &operator () (int, int);
 
      private:
         int nrows;
        int ncols;
         T **pntr;
   };
#endif
im trying to make the out of range exception in

template <typename T> T &Matriz <T> :: operator()(int rws, int clm) {

1
2
3
4
5
6
7
// try{
      return pntr[rws][clm];
// }
// catch{
//    cout << "Out Of Range" << endl;
// }
}

also i would like to know how to handle the invalid type exception

Thanks in advance
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder