in reply to How to get die() to stop printing a line number?

Why do you want to? Die is for handling exceptions in your program. If you have a large program then the line number is extremely useful. If you just want your program to end, use exit instead.

Lobster Aliens Are attacking the world!

Replies are listed 'Best First'.
Re: How to get die() to stop printing a line number?
by Abigail-II (Bishop) on Jul 01, 2003 at 23:22 UTC
    Strange. I usually am not interested at all on which line a program gave up and died. I want to know why it died. I generally don't care the program couldn't open a file on line 1273 - but I do care which file it couldn't open, and why.

    Abigail

      For me the question of where it died allows me to go there and start figuring out why it was doing what it did when it died. Therefore while where is in and of itself unimportant, it helps answer what I want answered.
        In the example I gave, a die after a failure of a system call (which is a very common usuage of die), I would not look at the program to solve the problem - because the problem lies elsewhere. So, why bother with the line number? It's irrelevant to both the programmer and the user.

        Abigail

      That's very foriegn to me. Say for instance I have a large program that has multiple files to open and I mistype a filename, either when I declare in some variable somewhere or even if I just used it in the open call itself. So now if I don't have a line number and the filename it spit back out was useless I have to go through the entire program to find where I made such a mistake. Even if its a variable that was declared elsewhere, the line number at least gives me a place to start. I may have forgotten the variable name I used, etc.

      For me an even more common use would be if a SQL query failed. Its extremely easy to have a syntax error in query, and it won't get caught until runtime. Sure I could print out the whole query and look for it, but a line number seems so much easier: fire up 'vim' <line-number> shift-G and there's the error.

      Lobster Aliens Are attacking the world!
        Well, assuming you print the name of the file that failed to open in the error message, a simple grep on the file name would find its declaration immediately - which got to be faster than first going to the line number, and then grepping for the variable name. (vi +/filename/ program.pl)

        Depending on your preference, you might be right about the SQL query (I usually write modules with just a handful of related queries in the same file, which would then be relatively small, so there's hardly any searching needed). But I was arguing against the sentiment one should always have to have the line number in a die message. The fact that there are cases where you might want to have the line numbers doesn't dispute that.

        Abigail