Getting Current Source Line Number

I am pulling my already sparse hair out trying to perform the most remedial of tasks: I am trying to trace my code execution to debug it and to log error messages, which is done in C with something like the ubiquitous
'printf ("%s:%d\n", __FILE__, __LINE__);'
I can't for the life of me find anything like __FILE__ and __LINE__ in Java.
How do I determine the current source line number??? I could live without the __FILE__ part if I had to, but the line number is imperative. Where do I get it?
Thanks,
Bill Rebey

"debug" still being a hard work in Java... the oldest Java nightmare :^)))
you may avoid this problem using labels in your code (the problem you must fill your code with debug stuff - if the code is a big one, you will get crazy about that :^) )
or you may adopt a tool able to trace your code execution....
JBuilder do it for you...
Togheter is another good software available out there
(unfortunatelly, both of them are really expensive...)
I don�t remember now about other tools.. (the java has a flag to produce debug output - check in the forum about the debug syntax....)

Similar Messages

  • How to get input source line number

    I wrote a XSLT transformation that checks the input XML for errors.
    When the transformer finds a problem, it can terminate with <xsl:message terminate="yes">, which outputs the line number within the transformer XML source. I do so in my implementation to indicate errors.
    But i need to output the line number of the input source, not that of the transformer source, because this is the location of the error.
    Anybody knows how to do this?
    How can i get the current line number of the input source XML text?

    Hello Fritz!
    XALAN reads the entire input file (SAX) before starting with transformation.
    So overriding the input stream is no way to find this line number.
    I think this would have to be a built-in XSLT functionality within the tag "xsl:message".

  • Source line number in exception trace

    Excuse me if the question is silly.
    When I print the stack trace after an exception has occured, how is it able to display the exact source line number 'cos the source file may or may not be accessible to the jvm. Obviously they don't keep source line-wise info in the class file,right?

    won't class files be large just because of the debug data?
    laurivasko@linux:~/java> javac HelloWorld.java
    laurivasko@linux:~/java> ls -la HelloWorld.class
    -rw-r--r--    1 laurivasko users         426 2004-06-26 20:07 HelloWorld.class
    laurivasko@linux:~/java> javac -g:none HelloWorld.java
    laurivasko@linux:~/java> ls -la HelloWorld.class
    -rw-r--r--    1 laurivasko users         341 2004-06-26 20:07 HelloWorld.classas you see, first case has file size of 426 bytes, and other one has wile size of 341 bytes, and that all with 5 line HelloWorld commandline application.
    // hopefully that answers your question.

  • STRANGER GETS MY LAND LINE NUMBER FROM MY IPHONE CALL

    Using my iPhone, I called a stranger in error.  He answered, whereby I realized my mistake.  Instead of being courteous, as I should have been, and saying, "Sorry, wrong number," I simply hung up.  This apparently upset him, because he subsequently called my land line and left a threatening message, telling me never to call again.  So, hmmm, how did he get my land line number?  I'm guessing because it showed up, on his end, when I initially called him with my iPhone.  It was associated with or attached to my iPhone number.  I know that when a certain relative calls me, more than one of her numbers shows up on my call-back notification.
    What do I do to prevent this?  I must be able to control and limit the information about me that people I call can get.

    There's absolutely no way your land line # was transmitted as CID when calling from your iPhone.  If this person found out your land line #, he looked it up based on the name and/or cell # of your iPhone. 
    The only way he could have your land line show when you called his cell phone is if he already has your full contact info in his phone, including  your land line - i.e. you are already known to him.
    To avoid this in the future:
    1. Disable caller id:  Settings > Phone > Show My Caller ID > OFF
    2. If you don't want to do that, have your carrier transmit only your cell # without your name.  Your name can still be researched, but usually require payment
    3. Get an unlisted land line phone.
    4. Research all the things that can be done with a baseball bat.

  • How can we get the selected line number from JTextArea ?

    how can we get the selected line number from JTextArea ? and want to insert line/string given line number into JTextArea??? is it possible ?

    Praitheesh wrote:
    how can we get the selected line number from JTextArea ?
    textArea.getLineOfOffset(textArea.getCaretPosition());
    and want to insert line/string given line number into JTextArea??? is it possible ?
    int lineToInsertAt = 5; // Whatever you want.
    int offs = textArea.getLineStartOffset(lineToInsertAt);
    textArea.insert("Text to insert", offs);

  • Trap the currently executing line number?

    Hi,
    how can one get the number of the currently executing line of code?
    Like what is generated when there are compilation/runtime errors.
    I saw LineNumberReader() & getLineNumber() but they seem to be for reading files or a jpanel (I think).
    thanks,
    HSC

    ok, with all your help I managed to get this:
                //----------------- stack trace for debugging ------------------           
                StackTraceElement[] e = new Throwable().getStackTrace();
                StackTraceElement stack[] = e;
                // stack[0] contains the method that created the exception.
                // stack[stack.length-1] contains the oldest method call.
                // Enumerate each stack element.
                //for (int i=0; i<stack.length; i++)
                int i=0;
                String filename = stack.getFileName();
    if (filename == null) {
    // The source filename is not available
    String className = stack[i].getClassName();
    String methodName = stack[i].getMethodName();
    boolean isNativeMethod = stack[i].isNativeMethod();
    int line = stack[i].getLineNumber();
    System.out.println(
    " >>className =" + className +
    " >> methodName =" + methodName +
    " >> line = " +line
    // } //end-for
    //----------------- stop stack trace for debugging ------------------
    Still don't quite understand it all but considering I've been learning java on my own for about 3 weeks I figure I'm doing better than a lot of newbies. - I am frustrated as hell, but I don't give up!
    thanks.
    Note: anyone looking for code examples you can look at: "The Java Developers Almanac 1.4" http://javaalmanac.com/

  • To get Current Business Partner number In BADi

    Hi All,
    In Tcode BP (for creating Business Partner) i am using BADi  'BUPA_GENERAL_UPDATE'. In this i want get Current Business partner No Assigned for the current Creation process.Suggest me how to get Current Businees Partner no assigned or current creation.
    (Actually in the program wher this BADi is calling there is internal table mem_but000 which has the but000 details incluiding what Business partner number assigned for current creation.Is it possible to get details from this itab in my BADi implementation Method.)

    Hi,..
    U can use field symbols and get the values of the internal table into ur BADI
    FIELD-SYMBOLS: <fs_wa> TYPE table .
    UNASSIGN <fs_wa>.
    ASSIGN ('(program name)mem_but000 ') TO <fs_wa> .
    program name is the name of the program where this internal table mem_but000 is having data..
    U will get all the entries of the internal table in field symbol..
    decalre internal table like mem_but000 and assign the filed symbol data into internal table .
    IF sy-subrc EQ 0.(sy-subrc check for the assign statement)
    t_mem_but000  = <fs_wa>.
    endif.
    regards
    Sheeba

  • Whow to get the error line number in Oracle 9i

    I am using Oracle 9i, In my procedure i am getting exception in When Others section, but unable to trace that from where it is throughing.... the procedure is about 2500 line of code. In Oracle 10g we can use dbms_utility.format_error_backtrace to catch the line number....
    So, is there any workaround in Oracle 9i to get the line number ????
    Thanks in Adance...

    Not sure, but the following might give you a good starter for ten....
    create or replace procedure who_called_me( owner      out varchar2,
                             name       out varchar2,
                             lineno     out number,
                             caller_t   out varchar2 )
    as
        call_stack  varchar2(4096) default dbms_utility.format_call_stack;
        n           number;
        found_stack BOOLEAN default FALSE;
        line        varchar2(255);
        cnt         number := 0;
    begin
        loop
            n := instr( call_stack, chr(10) );
            exit when ( cnt = 3 or n is NULL or n = 0 );
            line := substr( call_stack, 1, n-1 );
            call_stack := substr( call_stack, n+1 );
            if ( NOT found_stack ) then
                if ( line like '%handle%number%name%' ) then
                    found_stack := TRUE;
                end if;
            else
                cnt := cnt + 1;
                -- cnt = 1 is ME
                -- cnt = 2 is MY Caller
                -- cnt = 3 is Their Caller
                if ( cnt = 3 ) then
                    lineno := to_number(substr( line, 13, 6 ));
                    line   := substr( line, 21 );
                    if ( line like 'pr%' ) then
                        n := length( 'procedure ' );
                    elsif ( line like 'fun%' ) then
                        n := length( 'function ' );
                    elsif ( line like 'package body%' ) then
                        n := length( 'package body ' );
                    elsif ( line like 'pack%' ) then
                        n := length( 'package ' );
                    elsif ( line like 'anonymous%' ) then
                        n := length( 'anonymous block ' );
                    else
                        n := null;
                    end if;
                    if ( n is not null ) then
                       caller_t := ltrim(rtrim(upper(substr( line, 1, n-1 ))));
                    else
                       caller_t := 'TRIGGER';
                    end if;
                    line := substr( line, nvl(n,1) );
                    n := instr( line, '.' );
                    owner := ltrim(rtrim(substr( line, 1, n-1 )));
                    name  := ltrim(rtrim(substr( line, n+1 )));
                end if;
            end if;
        end loop;
    end;
    /

  • Get current weblogic version number

    Hi.
    I want as much as possible information from current ADF application instance. I know how to get ADF Faces version, User agent, Skin, Session ID, Java version,... I don't know hot to get current application's server version and name.
    Any ideas?
    10x
    Regards

    It is old but still working:
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.text.DateFormat;
    import java.util.Date;
    import java.util.Enumeration;
    import java.util.Properties;
    import javax.servlet.*;
    import javax.servlet.http.*;
    /*http://127.0.0.1:7101/yourwebappname/servlet/SuperSnoop*/
    public class SuperSnoop extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    private String makeTitle( String title )
    return new String("<H2>"+title+"</H2>\n");
    private String showRequestParams( HttpServletRequest request )
    StringBuffer sb = new StringBuffer(512);
    Enumeration e = request.getParameterNames();
    String key = null;
    String value = null;
    sb.append(makeTitle("Request Parameters"));
    sb.append("<table>");
    while( e.hasMoreElements() ){
    key = (String)e.nextElement();
    value = request.getParameter(key);
    sb.append( makeRow( key, value ));
    sb.append("</table>");
    return sb.toString();
    private String showInitParams() {
    StringBuffer sb = new StringBuffer(512);
    ServletContext context = getServletContext();
    Enumeration e = context.getInitParameterNames();
    String key = null;
    String value = null;
    sb.append(makeTitle("Initialization Parameters"));
    sb.append("<table>");
    while( e.hasMoreElements() ){
    key = (String)e.nextElement();
    value = context.getInitParameter(key);
    sb.append( makeRow( key, value ));
    sb.append("</table>");
    return sb.toString();
    private String showServletContextInfo()
    StringBuffer sb = new StringBuffer(512);
    ServletContext context = getServletContext();
    sb.append(makeTitle("Servlet Context"));
    sb.append("<table>");
    sb.append( makeRow( "Server Info", context.getServerInfo()));
    sb.append( makeRow( "Servlet Context Name", context.getServletContextName()));
    sb.append( makeRow( "Real Path", context.getRealPath("/")));
    sb.append("</table>");
    return sb.toString();
    private String showContextAttributes() {
    StringBuffer sb = new StringBuffer(512);
    ServletContext context = getServletContext();
    Enumeration e = context.getAttributeNames();
    String key = null;
    String value = null;
    sb.append(makeTitle("Servlet Context Attributes"));
    sb.append("<table>");
    while( e.hasMoreElements() ){
    key = (String)e.nextElement();
    value = context.getAttribute(key).toString();
    sb.append( makeRow( key, value ));
    sb.append("</table>");
    return sb.toString();
    private String showSysProps() {
    StringBuffer sb = new StringBuffer(512);
    Properties p = System.getProperties();
    Enumeration e = p.propertyNames();
    String key = null;
    String value = null;
    sb.append(makeTitle("System Properties"));
    sb.append("<table>");
    sb.append(makeRow("System Time", today() ));
    while( e.hasMoreElements() ){
    key = (String)e.nextElement();
    value = p.getProperty( key );
    sb.append( makeRow( key, value ));
    sb.append("</table>");
    return sb.toString();
    private String showHeaders( HttpServletRequest request ) {
    StringBuffer sb = new StringBuffer(512);
    Enumeration e = request.getHeaderNames();
    String key = null;
    String value = null;
    sb.append( makeTitle("Request Headers"));
    sb.append("<table>");
    while( e.hasMoreElements() ){
    key = (String)e.nextElement();
    value = request.getHeader(key);
    sb.append( makeRow( key, value ));
    sb.append("</table>");
    return sb.toString();
    private String showRequestInfo(HttpServletRequest request) {
    StringBuffer sb = new StringBuffer(512);
    sb.append(makeTitle( "Request Info"));
    sb.append("<table>\n");
    sb.append( makeRow( "ContextPath", request.getContextPath() ));
    sb.append( makeRow( "Method", request.getMethod() ));
    sb.append( makeRow( "RequestURL", request.getRequestURL().toString()));
    sb.append( makeRow( "ServletPath", request.getServletPath() ));
    sb.append( makeRow( "CharacterEncoding", request.getCharacterEncoding() ));
    sb.append( makeRow( "ContentType", request.getContentType() ));
    sb.append( makeRow( "RemoteAddress", request.getRemoteAddr() ));
    sb.append( makeRow( "RemoteHost", request.getRemoteHost() ));
    sb.append( makeRow( "Scheme", request.getScheme() ));
    sb.append( makeRow( "ServerName", request.getServerName() ));
    sb.append( makeRow( "ServerPort", Integer.toString(request.getServerPort()) ));
    sb.append("</table>\n");
    return sb.toString();
    private String makeRow( String left, String right ) {
    StringBuffer sb = new StringBuffer(128);
    sb.append( "<tr>\n" );
    sb.append( "\t<td>"+left+"</td>\n");
    sb.append( "\t<td>"+right+"</td>\n");
    sb.append( "</tr>\n" );
    return sb.toString();
    private String today()
    Date now = new Date();
    DateFormat dateFormatter = DateFormat.getDateTimeInstance();
    return dateFormatter.format( now );
    public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
    IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>SysProps Servlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println( today() );
    out.println( showHeaders(request) );
    out.println( showRequestInfo(request) );
    out.println( showRequestParams(request) );
    out.println( showServletContextInfo() );
    out.println( showContextAttributes() );
    out.println( showInitParams() );
    out.println( showSysProps() );
    out.println("</table>");
    out.println("</body>");
    out.println("</html>");
    out.close();
    public void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
    IOException {
    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>SuperSnoop</title></head>");
    out.println("<body>");
    out.println("<p>The servlet has received a POST. This is the reply.</p>");
    out.println("</body></html>");
    out.close();
    }

  • How to get PL/SQL line number ?

    Hello, All !
    I have an Error pointing to Line number - "ORA-06512: at "..._PKG", line 295
    How do I find out in physical code exactly where this line is ? I used SQL Navigator (it has line count) but It didn't match ! (Function names different in Error message and in Script Editor window and it pointed to a blank line). Does line count start from Package Spec or Body ?
    Please Help,
    Thanx !

    The line number is relative to the first line of the body. The most definitive way to identify the exact line would be to use USER_SOURCE ...
    SELECT TEXT
    FROM USER_SOURCE
    WHERE NAME = ...
    AND LINE = 295
    Richard

  • Re: GETTING AN ON LINE TELEPHONE NUMBER

    triggerrodney wrote:
    I TRIED TO GET AN ON LINE NUMBER, HOWEVER THE SYSTEM LISTED A NUMBER OF COUNTIES IN THE UK. UNFORTUNATELY NOTHING FOR SUFFOLK OR MY PREFIX. 01502.
    CAN YOU PLEASE HELP.
    Unfortunately, Skype isn't able to provide Online Numbers in all area codes of many countries, including the UK.  If you want an Online Number, you would have to select one from the list of area codes/cities that Skype offers in the UK. 
    Patrick
    Location/Ubicacion: Arizona USA
    Time Zone/Hora Local: UTC/GMT -7
    If this message has adequately addressed your issue, please click on the “Accept as Solution” button. If you found a post useful then please "Give Kudos" at the bottom of my post, so that this information can benefit others.
    Si esto mensaje le ha ayudado, por favor haga clic en "Aceptar como solución". Si encuentra un mensaje útil, por favor "Da Kudos" al final del mensaje, por lo que esta información puede beneficiar a otros.
    I am not a Skype employee. No soy un empleado de Skype.

    You can do a test, but the broadband will drop for a short while. If you leave your Internet browser on the same page, it will re-connect and display the test results.
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • Trapping line number/source file where exception occured

    Hi,
    How can we trap the line number where an exception was thrown and then store this information in a local data object? The line number appears in the stack trace but the only methods i can find for extracting info from the stack trace seem to write onto a file and not a local object.
    Appreciate any suggestions
    -Nikhil

    JDK 1.4 adds a getStackTrace() method to class Throwable. getStackTrace() returns an array of StackTraceElement objects, from which you can get file name/line number info and more.
    prior to JDK 1.4, your best bet would be to do a printStackTrace() to a StringWriter, and parse the resultant string. however, i believe the stack trace format is not platform-independent, so if you're writing something that will be run on different VMs, beware.

  • Link between schedule Line Number and Delivery

    Is there a link between Schedule line Number and Delivery number ?
    Eg. Line item 10 with quantity 100. 
    has 5 schedule lines..with 5 different delivery dates.
    1 .  quanity 40
    2.   quantity 30
    3.   quantity 20
    4.   quanity  6
    5    quantity  4
    For schedule line 1, 2 deliveries were created,
    one      with quantity 20
    another with quantity 15
    quantity 5 is still not delivered.
    also schedule lines 2,3,4 and 5 are fully delivered.
    Is there any table, FM etc in SAP which will give me the link between the schedule line and delivery number ?
    Total deliveries created : 6. - But which delivery corresponds to which schedule line ?
    Please dont tell me to look VGBEL and VGPOS.. that will just give line item number 10.. I need to get the schedule line number.
    Also, RV_SCHEDULE_CHECK_DELIVERIES --> will give me the delivered quantity against each schedule line.
    My purpose is to create an ontime delivery report .
    a report which list each schedule lines, and tell, how many shipments were late/ontime/early etc..
    and for Late ones, how many days late has to be found.
    this is where i need the delivery.
    No. Of days Late = Actual GI Date - Planned GI Date.
    Actual GI date is in the delivery.
    Any suggestions ?
    Thank you in advance.

    Hi,
    Check in the below link.
    relation between VBEP-ETENR and LIKP-VBELN
    Thanks,
    Sree.

  • On-line Number in Canada

    Hi I am in Victoria BC Canada and would like to get a on-line number when I click on Canada I get a message that says un avaiable is this just temporay ?
    Thanks
    Coachrobwille

    Hi, coachrobwille, and welcome to the Community,
    There is a lot of discussion on this topic here in the Community.  Please see these threads as examples:
    http://community.skype.com/t5/Idea-garage/Oh-canada-eh/m-p/1165112#M1150
    http://community.skype.com/t5/Online-Number/Online-Number-for-CANADA/m-p/1087128#M6722
    So, the short answer is there are no Skype On-Line Numbers available for Canada at this time. 
    Best regards,
    Elaine
    Was your question answered? Please click on the Accept as a Solution link so everyone can quickly find what works! Like a post or want to say, "Thank You" - ?? Click on the Kudos button!
    Trustworthy information: Brian Krebs: 3 Basic Rules for Online Safety and Consumer Reports: Guide to Internet Security Online Safety Tip: Change your passwords often!

  • How to find dynamically the current line number in the source file

    Is there a mechanism like __LINE__ and __FILE__ macro in C to get dynamically
    the current line number and file name of a source file?

    Don't know - but others have asked too. Have you searched the forum? For example:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=210496

Maybe you are looking for

  • Windows Vista Home Basic 64-bit

    I'm looking at the customisable configurations, and I see that you offer 8GB RAM but that a 64-bit system is required to support it. At the same time, the only option that explicity says it's 64-bit is the Business edition of Vista, which I definitel

  • Sprite won't respond to custom event

    I've got an app where numerous Sprite objects are being placed on the stage, and then when an event occurs (mouse click most likely) I want all the Sprites to move, independently, based upon an algorithm that each Sprite has.  I can't get the Sprite

  • Emac games

    Hi, I wonder if anyone would care to recommend some games that : a) Would be suitable for an older eMac (700MHz, about 500MB RAM). b) Install with minimal hassle c) Offer good gameplay for 8 - 12 year old boys. d) are readily available through new or

  • SocketChannel in non-blocking mode

    invoke these channel's write(Buffer) method, it will return immediately, how to know when buffer data have been send completely

  • My ipod touch 3 keeps turning itself off every few minutes

    i just updated to ios 5.0.1 or watever, and now about every 5 minutes it keeps full turning itself off (like if you hold power button) help!!!!!!!