2 Replies - 388 Views - Last Post: 16 June 2011 - 06:22 AM Rate Topic: -----

#1 EpicTTR  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 15-June 11

Is there any form of try-catch with multiple catches?

Posted 15 June 2011 - 08:23 PM

So in my program, I need to do something that will try one thing, and if that fails, move on to another.

I've made a program that encrypts another program and then attaches a stub onto that encrypted program, so the stub of code can later decrypt and run the rest of the program.

The thing is, there are four possible encryption algorithms that can be applied to the program initially, so there are four possible decryption algorithms.

I need either a way to detect which algorithm it has been encrypted with, or a way to try all the other algorithms against it.
Is there something I could do that with? Like a try-catch with multiple catches?

Is This A Good Question/Topic? 0
  • +

Replies To: Is there any form of try-catch with multiple catches?

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4312
  • View blog
  • Posts: 7,467
  • Joined: 08-June 10

Re: Is there any form of try-catch with multiple catches?

Posted 15 June 2011 - 09:56 PM

Well, trys do support multiple catches, but not really in the way you want. It's more a way to handle different exceptions differently.

The way I'd do this is make a method for each one. The method should return null if it catches an exception. Then you can just stack if-else statements.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,357
  • Joined: 02-June 10

Re: Is there any form of try-catch with multiple catches?

Posted 16 June 2011 - 06:22 AM

As Curtis mentioned try-catch handles multiple catch blocks.
But it sounds more like you need a switch...case construct.

I assume that since you wrote the encryption scheme you planned ahead enough to write *which* scheme you used in the file header - or did something similar. That there is some tell-tale indication of which scheme you used.

So read the header, determine the scheme, feed that to a switch...case block to do the decoding.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1