Community
    • Login

    Plugin Exception Handling c#

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    3 Posts 2 Posters 840 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • James PlahitkoJ Offline
      James Plahitko
      last edited by

      I am writing my first plugin. I attempted to test a try-catch in a function using a divide by zero statement. It seems Notepad++ catches all exceptions, and in my test case, it reports, dumps and exits rather harshly.

      Is it possible and is there a recommended method for catching an exception before it bubbles up to Notepad++?

      Mark OlsonM 1 Reply Last reply Reply Quote 2
      • Mark OlsonM Offline
        Mark Olson @James Plahitko
        last edited by Mark Olson

        @James-Plahitko

        Is it possible and is there a recommended method for catching an exception before it bubbles up to Notepad++?

        What language are you using? Edit: oh duh, it’s C#, look at the post title.
        The best way to catch an exception before it bubbles up in NPP is just the language’s default way of catching exceptions.

        Now would be a very natural place to include examples of proper try/catch syntax, but I’m not going to discuss best practices for catching exceptions in programming languages, because that is a general programming issue and not a Notepad++ issue, and thus not appropriate for this forum.
        That said, there is one important related question that is more specific to Notepad++, and that is whether to notify the user (via a message box, or audible ding, or whatever) when an error occurs.

        That said, most plugins are open-source, which means you can look at the source code of your favorite plugin (in the same language you’re using) to get a sense of how they handle errors.

        1 Reply Last reply Reply Quote 4
        • James PlahitkoJ Offline
          James Plahitko
          last edited by

          My issue was two-fold. The try-catch syntax was basically correct. However, I was technically sloppy in visual studio allowing the exception type to auto-fill the ArgumentException type. The “divide by zero” exception was not being caught.

          The second issue was re-throwing the exception and Notepad was picking it up. In this case, I don’t want Notepad to react. Life is good now.

          Thank you Mark for your suggestions.

          1 Reply Last reply Reply Quote 1

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors