• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set breakpoint programmatically under Eclipse?

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have my own ErrorHandler class with a method breakpoint() that does nothing but beg user to "set breakpoint here". It's a bit like a low-tech virus from an old joke, that asks you to delete all your files and forward it to all your friends. Any way I can make Eclipse set a breakpoint, from my Java code?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. For one thing, what would it do if you weren't running under a debugger? For another thing, the debugger client is what works with breakpoints, and it's typically running in a different VM which may be on a different computer, and it might not even be a Java program at all, since the low-level debugger communications channel involves text commands. Meaning that if I wanted to write a Java debugger in Python, I could do so.

In the case of Eclipse, specifically, you might be able to create an Eclipse plug-in that talked to the Eclipse debugger client, but that seems like a lot of work. It's easier just to throw some sort of Breakpoint exception and tell the Eclipse debugger to halt on breakpoint. I often do that to catch NullPointerExceptions in the act, but any Exception will do, including one you make up for just that purpose.
 
Jane Jukowsky
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:No. For one thing, what would it do if you weren't running under a debugger?


I don't know.. recover gracefully? I did it in 1999 for VisualAgeForJava, it took 3 lines of code and worked fine.

For another thing, the debugger client is what works with breakpoints, and it's typically running in a different VM which may be on a different computer, and it might not even be a Java program at all, since the low-level debugger communications channel involves text commands. Meaning that if I wanted to write a Java debugger in Python, I could do so.


You are right in principle, but I had specified Eclipse.

In the case of Eclipse, specifically, you might be able to create an Eclipse plug-in that talked to the Eclipse debugger client, but that seems like a lot of work.
Is it? I did not know that, thanks! I was hoping it would be as easy as Visual Age.

It's easier just to throw some sort of Breakpoint exception and tell the Eclipse debugger to halt on breakpoint. I often do that to catch NullPointerExceptions in the act, but any Exception will do, including one you make up for just that purpose.


That's close to what I am doing now, but I "clear all breakpoints" often, and I start with a clean workspace often enough, and will potentially have other users do the same; so it's not ideal.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic