Try Catch

  • Thread starter Thread starter Gavaskar
  • Start date Start date
G

Gavaskar

Should I be able to put a Try Catch inside a class?

class Myclass
{
try
{
// create something, streamwritter
}
catch()
{
// catch error
}




} / end class
 
Gavaskar said:
Should I be able to put a Try Catch inside a class?

class Myclass
{
try
{
// create something, streamwritter
}
catch()
{
// catch error
}




} / end class

Try/catch blocks only go in methods.
 
Gavaskar said:
Should I be able to put a Try Catch inside a class?

class Myclass
{
try
{
// create something, streamwritter
}
catch()
{
// catch error
}




} / end class

What you probably are wanting to do is catch an exception thrown in an
initialization. Instead perform the allocation and assignment inside the
constructor, you can have try-catch in a constructor.
 
Back
Top