Try Catch

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
 
H

Heandel

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.
 
B

Ben Voigt [C++ MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top