Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6158877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:02:04+00:00 2026-05-23T21:02:04+00:00

In Java it’s written like this.. when I was porting this code… realizied there

  • 0

In Java it’s written like this.. when I was porting this code… realizied there is no such thing as
break <label> and continue <label>.

I know those commands were not included because there HAS to be a cleaner way of doing this when using a goto with a command..

But I ended up using.. the C# code below any way to rewrite it cleaner?

Java Code

for(JClass c : classes) {
    for(JMethod m : c.getMethods()) {
        JCode code = m.getCode();
        if(code == null)
            continue;
        label: for(int index = 0; index < code.getExceptionLookupTable().length; index++) {
            JException e = code.getExceptionTable().get(index);
            for(int index2 = e.getStartIndex(); index2 < e.getEndIndex(); index2++)
                if(code.getInstruction(index2).getOpcode() == NEW && ((NEW) code.getInstruction(index2)).getType().equals("java/lang/RuntimeException"))
                    continue label;
                if(e.getCatchTypeClassName().equals("java/lang/RuntimeException")) {
                    for(int index = e.getHandlerIndex(); index < code.getInstrLength(); index++) {
                        JInstruction instr = code.getInstruction(index);
                        if(instr.getOpcode() == ATHROW)
                            break;
                        else if(instr instanceof ReturnInstruction)
                            break label;
                    }
                    removeStuff(code, ei--);
                }
            }
    }
}

C# Code.

foreach(JClass c in classes) {
    foreach(JMethod m in c.getMethods()) {
        JCode code = m.getCode();
        if(code == null)
            continue;

        for(int index = 0; index < code.getExceptionTable().Length; index++) {
            bool continueELoop = false;
            bool breakELoop = false;
            JException e = code.getExceptionTable().get(index);
            for(int index2 = e.getStartIndex(); index2 < e.getEndIndex(); index2++) {
                if(code.getInstruction(index2).getOpcode() == JInstructions.NEW && ((NEW) code.getInstruction(index2)).getType().Equals("java/lang/RuntimeException")) {
                    continueELoop = true;
                    break;
                }
            }
            if(continueELoop) continue;

            if(e.getCatchTypeClassName().Equals("java/lang/RuntimeException")) {
                for(int index = e.getHandlerIndex(); index < code.getInstrLength(); index++) {
                    JInstruction instr = code.getInstruction(index);
                    if (instr.getOpcode() == JInstructions.ATHROW) {
                        break;
                    } else if (isReturnInstruction(instr)) {
                        breakELoop = true;
                        break;
                    }
                }
                removeStuff(code, ei--);
            }
            if (breakELoop) break;
        }
    }
}

You can see when looking at the Java version then looking at the ported C# version.. the clean feeling goes away. Did I make some mistakes that can make the code shorter? or nicer looking? thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:02:05+00:00Added an answer on May 23, 2026 at 9:02 pm

    I guess, in C# you would never write such ugly code in the first place.

    Here’s your code refactored into multiple methods and to use LINQ with a fictional class hierarchy:

    IEnumerable<JCode> GetCodes(IEnumerable<JClass> classes)
    {
        return from @class in classes
               from method in @class.Methods
               where method.Code != null
               select method.Code;
    }
    
    IEnumerable<Tuple<JCode, JException>> GetCandidates(IEnumerable<JCode> codes)
    {
        return from code in codes
               from ex in code.ExceptionTable
               where !code.Instructions
                          .Skip(ex.Start)
                          .Take(ex.End - ex.Start + 1)
                          .Any(i => i.OpCode == New && ...)
               select Tuple.Create(code, ex);
    }
    

    and then

    void RewriteMethods(IEnumerable<JClass> classes)
    {
        var codes = GetCodes(classes);
    
        var candidates = GetCandidates(codes);
    
        foreach (var candidate in candidates)
        {
            var code = candidate.Item1;
            var ex = candidate.Item2;
    
            var instructionsToRemove = code.Instructions
                                           .Skip(ex.HandlerStart)
                                           .TakeWhile(i => i.OpCode != Return)
                                           .Where(i => i.OpCode == AThrow);
    
            code.RemoveAll(instructionsToRemove);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Java question) If I reference a field in an inner class, does this cause
Java is nearing version 7. It occurs to me that there must be plenty
java.lang.annotation.ElementType : A program element type. The constants of this enumerated type provide a
Java Q: I like CSS for simple web pages but loathe it when it
Java is the supported language by .NET. Where is it used ? Is there
Java has generics and C++ provides a very strong programming model with template s.
Java has a convenient split method: String str = The quick brown fox; String[]
Java Newbie here. I have a JFrame that I added to my netbeans project,
Java is one of my programming languages of choice. I always run into the
Java SE 6 (64 bit only) is now on OS X and that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.