A
Allie
Hi, all.
I've never been any good at handling exceptions... So I need your
help.
Within a try{ } block, I have to call a function that has to throw its
own exception. How should I go about doing this?
try {
checkNullHeader( sHeader, ref status );
// ...
}
// ...
// definition of checkNullHeader
void checkNullHeader( AuthHeader sHeader, ref status status )
{
// if token is null or empty, do not even try to authenticate
if( sHeader == null || sHeader.Token == null ||
sHeader.Token.Equals( "" ) )
{
try {
status.Code = Status.StatusCode.UNAUTHORIZED;
status.Description = "Unauthorized";
throw new Exception( "Unauthorized" );
}
catch( Exception e )
{
Console.WriteLine( "Exception caught here:" + e.ToString ( ) );
}
}
}
Is something like this legal? Am I even throwing the exception
correctly? (Seriously. Exceptions are very foreign to me.) Help me!
Thanks.
Allie
I've never been any good at handling exceptions... So I need your
help.
Within a try{ } block, I have to call a function that has to throw its
own exception. How should I go about doing this?
try {
checkNullHeader( sHeader, ref status );
// ...
}
// ...
// definition of checkNullHeader
void checkNullHeader( AuthHeader sHeader, ref status status )
{
// if token is null or empty, do not even try to authenticate
if( sHeader == null || sHeader.Token == null ||
sHeader.Token.Equals( "" ) )
{
try {
status.Code = Status.StatusCode.UNAUTHORIZED;
status.Description = "Unauthorized";
throw new Exception( "Unauthorized" );
}
catch( Exception e )
{
Console.WriteLine( "Exception caught here:" + e.ToString ( ) );
}
}
}
Is something like this legal? Am I even throwing the exception
correctly? (Seriously. Exceptions are very foreign to me.) Help me!
Thanks.
Allie